以下是一个Python脚本,可以计算两个图像之间的单应性,并将一个期望的点从一个图像映射到另一个图像。
然而,当我显示包含映射点的图像时,会返回以下错误:
据我的了解,这个错误意味着分配给透视变换函数的参数不正确或没有被读取。我在读取步骤中检查了两张图片,一切都很好。所以谁知道为什么会发生这种情况吗?
提前致谢 卡利德
import cv2
import numpy as np
if __name__ == '__main__' :
# Read source image.
im_src = cv2.imread(r'C:/Users/kjbaili/.spyder-py3/webcam_calib/homography/khaledd 35.0 sec.jpg')
# Five corners of the book in source image
pts_src = np.array([[281, 238], [325, 297], [283, 330],[248, 325],[213, 321]])
# Read destination image.
im_dst = cv2.imread(r'C:/Users/kjbaili/.spyder-py3/webcam_calib/homography/20.jpg')
# Five corners of the book in destination image.
pts_dst = np.array([[377, 251],[377, 322],[316, 315],[289, 284],[263,255]])
# Calculate Homography
h, status = cv2.findHomography(pts_src, pts_dst)
# provide a point i wish to map from image 1 to image 2
a = np.array([[260, 228]])
pointsOut = cv2.getPerspectiveTransform(a, h)
# Display image
cv2.imshow("treced_point_image", pointsOut)
cv2.waitKey(0)
cv2.destroyAllWindows()
然而,当我显示包含映射点的图像时,会返回以下错误:
error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\core\src\matmul.dispatch.cpp:531:
error: (-215:Assertion failed) scn + 1 == m.cols in function 'cv::perspectiveTransform'
据我的了解,这个错误意味着分配给透视变换函数的参数不正确或没有被读取。我在读取步骤中检查了两张图片,一切都很好。所以谁知道为什么会发生这种情况吗?
提前致谢 卡利德