把npy文件处理成图形

import numpy as np
import os
# import tensorflow as tf
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import torch

H = np.loadtxt("./homography/hotel.txt")
# H = torch.pinverse(H)

for j in range(0,1):
    data_dir = './hotel-test/coor'+ str(j) + '.npy'
    data_dir1 = './hotel-pre/coor'+ str(j) + '.npy'
    im_file = './ETH/seq_hotel/images/'+str(j+80) + '.jpg'

# print(all_files)
# print(all_files)
coor_g = np.load(data_dir)  # [20,2,2]
coor_p = np.load(data_dir1)
# coor = np.load(dataset_path)  # [20,2,2]
# print(coor.shape[0])
ones = np.ones([coor_p.shape[0], coor_p.shape[1], 1])
coor1 = np.moveaxis(coor_p, 1, 0)  # [2,20,2]
coor2 = np.moveaxis(coor_g, 1, 0)
# print("2: ",coor2)
# print("1: ", coor1)
# coor = np.concatenate([coor, ones], axis=-1)  # [20,2,3]
coor_p = np.concatenate([coor_p, ones], axis=-1)
coor_g = np.concatenate([coor_g, ones], axis=-1)
# coor = np.moveaxis(coor, 2, 1)  # [20,3,2]
coor_p = np.moveaxis(coor_p, 2, 1)
coor_g = np.moveaxis(coor_g, 2, 1)
# pixel_coor = np.matmul(H, coor)  # [20,3,2]
pixel_coor_g = np.matmul(H, coor_g)
pixel_coor_p = np.matmul(H, coor_p)
# pixel_coor = np.moveaxis(pixel_coor, 1, 2)  # [20,2,3]
pixel_coor_g = np.moveaxis(pixel_coor_g, 1, 2)
pixel_coor_p = np.moveaxis(pixel_coor_p, 1, 2)
# pixel_coor[:, :, 0] = pixel_coor[:, :, 0] / pixel_coor[:, :, 2]  # [u,v,1]
# pixel_coor[:, :, 1] = pixel_coor[:, :, 1] / pixel_coor[:, :, 2]  # [u,v,1]
pixel_coor_g[:, :, 0] = pixel_coor_g[:, :, 0] / pixel_coor_g[:, :, 2]  # [u,v,1]
pixel_coor_g[:, :, 1] = pixel_coor_g[:, :, 1] / pixel_coor_g[:, :, 2]
pixel_coor_p[:, :, 0] = pixel_coor_p[:, :, 0] / pixel_coor_p[:, :, 2]  # [u,v,1]
pixel_coor_p[:, :, 1] = pixel_coor_p[:, :, 1] / pixel_coor_p[:, :, 2]
# pixel_coor = pixel_coor[:, :, :2]
pixel_coor_g = pixel_coor_g[:, :, :2]
pixel_coor_p = pixel_coor_p[:, :, :2]
# pixel_coor = np.moveaxis(pixel_coor, 1, 0)  # [2,20,3]
pixel_coor_g = np.moveaxis(pixel_coor_g, 1, 0)
pixel_coor_p = np.moveaxis(pixel_coor_p, 1, 0)
# pixel_coor = pixel_coor.astype(int)
pixel_coor_g = pixel_coor_g.astype(int)
pixel_coor_p = pixel_coor_p.astype(int)

for i in range(coor_p.shape[2]):
    x_p = pixel_coor_p[i, :, 0].astype(int)
    y_p = pixel_coor_p[i, :, 1].astype(int)
    x_g = pixel_coor_g[i, :, 0].astype(int)
    y_g = pixel_coor_g[i, :, 1].astype(int)

    # if i == 0:
    # plt.plot(x_g, y_g, 'b.', lw=2.5)
    # plt.plot(x_p[:8], y_p[:8], 'r.', lw=2.5)
    plt.plot(y_g, x_g, 'b.', lw=2.5)
    plt.plot(y_p[-13:], x_p[-13:], 'r.', lw=2.5)

img = mpimg.imread(im_file)
plt.imshow(img)

plt.xlabel("x")
plt.ylabel('y')
# plt.axis([-800, 1600, -800, 1600])
plt.title("picture" + str(500))
plt.legend()
plt.grid()
plt.show()

你可能感兴趣的:(python,matlab,numpy)