Skip to content
Advertisement

error: (-215:Assertion failed) scn + 1 == m.cols in function ‘cv::perspectiveTransform’

Below is a python script that calculates the homography between two images and then map a desired point from one image to another

JavaScript

However, when i display the image that contains the mapped point it returns the following error:

JavaScript

According to my knowledge this error means that parameter assigned to the function perspective transform is not correct or not being read. I checked the two images at the reading step and everything is fine. So anyone knows why this happens?

Thanks in advance Khaled

Advertisement

Answer

You are passing wrong arguments to cv2.getPerspectiveTransform(). The function expects a set of four coordinates in the original image and the new coordinates in the transformed image. You can directly pass the pts_src and pts_dst to the function and you will get the transformation matrix. You can then get the transformed coordinates for point “a” by matrix multiplication like a_transformed = np.dot(matrix, a).

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement