Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV cv2 perspective transformation matrix multiplication

I am trying to combine a series of warpPerspective into one by combining the matrices generated by getPerspectiveTransform. If I multiply them together using cv2.multiply the resulting matrix doesn’t work. Example for just two transformations:

src = np.array([[0,0],[0,480],[640,480],[640,0]],np.float32) dst = np.array([[-97,-718],[230,472],[421,472],[927,-717]],np.float32)

retval = cv2.getPerspectiveTransform(src, dst); test = cv2.multiply(retval.copy(),retval.copy())

img1 = cv2.warpPerspective(img1,test,(640,480))

img2 = cv2.warpPerspective(img2,retval,(640,480)) img2 = cv2.warpPerspective(img2,retval,(640,480)) Why aren't img1 and img2 the same? How do I combine the perspective transformation matrices?

Thanks

OpenCV cv2 perspective transformation matrix multiplication

I am trying to combine a series of warpPerspective into one by combining the matrices generated by getPerspectiveTransform. If I multiply them together using cv2.multiply the resulting matrix doesn’t work. Example for just two transformations:

src = np.array([[0,0],[0,480],[640,480],[640,0]],np.float32) np.array([[0,0],[0,480],[640,480],[640,0]],np.float32)

dst = np.array([[-97,-718],[230,472],[421,472],[927,-717]],np.float32)

retval = cv2.getPerspectiveTransform(src, dst); dst);

test = cv2.multiply(retval.copy(),retval.copy())

img1 = cv2.warpPerspective(img1,test,(640,480))

img2 = cv2.warpPerspective(img2,retval,(640,480)) cv2.warpPerspective(img2,retval,(640,480))

img2 = cv2.warpPerspective(img2,retval,(640,480)) cv2.warpPerspective(img2,retval,(640,480))

Why aren't img1 and img2 the same? How do I combine the perspective transformation matrices?

Thanks

click to hide/show revision 3
retagged

OpenCV cv2 perspective transformation matrix multiplication

I am trying to combine a series of warpPerspective into one by combining the matrices generated by getPerspectiveTransform. If I multiply them together using cv2.multiply the resulting matrix doesn’t work. Example for just two transformations:

src = np.array([[0,0],[0,480],[640,480],[640,0]],np.float32)

dst = np.array([[-97,-718],[230,472],[421,472],[927,-717]],np.float32)

retval = cv2.getPerspectiveTransform(src, dst);

test = cv2.multiply(retval.copy(),retval.copy())

img1 = cv2.warpPerspective(img1,test,(640,480))

img2 = cv2.warpPerspective(img2,retval,(640,480))

img2 = cv2.warpPerspective(img2,retval,(640,480))

Why aren't img1 and img2 the same? How do I combine the perspective transformation matrices?

Thanks