【发布时间】:2021-08-24 03:42:36
【问题描述】:
我正在尝试根据第二张图片更改第一张图片的视角。为了找到单应矩阵,我在两个图像中找到了一个共同对象(白色公告板)的四个坐标。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
img1 = cv2.imread("rgb per.jpg")
img2 = cv2.imread("IR per.jpg")
img_1_coor = np.float32([[1178,425], [1201,425], [1178,439], [1201,439], [1551,778]]) #coordinate of white notice board in rgb image
img_2_coor = np.float32([[370,98], [381,103], [367,107], [380,112], [498,332]]) #coordinate of same object in IR image
for x in range(0,4):
cv2.circle(img1,(img_1_coor[x][0],img_1_coor[x][1]),5,(255,0,0),1)
matplotlib.rcParams['figure.dpi'] = 300
#plt.imshow(img1) #this verified that the found coordinates are correct
#P = cv2.getPerspectiveTransform(img_1_coor,img_2_coor)
H, s = cv2.findHomography (img_1_coor,img_2_coor)
print(s)
perspective = cv2.warpPerspective(img1, H, img2.shape[:2])
plt.imshow(perspective)
#the resulting image
Output image 我希望输出类似于图像 1,视点(摄像机角度)作为图像 2。如果这是不可能的,反之亦然,将图像 2 的视点作为图像 1 也会有所帮助。
谁能告诉我是否可以使用图像中对象的坐标来改变全图的视角,如果可以,我的代码有什么问题吗?
【问题讨论】:
标签: python deep-learning opencv-python vision