我正在尝试使用opencvpython包执行单应性透视转换。在
我有一个背景和前景图像,并希望执行透视变换,并在给定四个(x,y)坐标的背景图像上缝合前景图像,如下所示:
bgImg = cv2.imread(BACK_PATH, cv2.IMREAD_COLOR)
fgImg = cv2.imread(FORE_PATH, cv2.IMREAD_COLOR)
bgHeight, bgWidth, dpt = bgImg.shape
origImageCoords = np.array([(0, 0),
(0, bgHeight),
(bgWidth, bgHeight),
(bgWidth, 0)])
stitchingCoords = []
def transformPerspective():
y0 = 285
y1 = 400
x0 = 447
x1 = 600
stitchingCoords.append((x0, y0))
stitchingCoords.append((x0, y1))
stitchingCoords.append((x1, y1))
stitchingCoords.append((x1, y0))
homography = cv2.findHomography(origImageCoords, np.array(stitchingCoords))
dst_corners = cv2.warpPerspective(src=fgImg, M=homography[0], dsize=(bgWidth, bgHeight))
showFinal(bgImg, dst_corners)
在使用cv2.findhomography()
完成透视变换后,我使用适当的遮罩遮罩前景和背景图像,并将它们添加到一起,如下所示:
问题是,查找结果是错误的,因为转换后的前景图像没有缝合到我用来查找单应性的四个坐标内。在
有人能告诉我为什么会发生这个错误吗?在
目前没有回答
相关问题 更多 >
编程相关推荐