Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using getPerspective to warp image to forward facing

I have an image that I want to stretch to cover the entire screen after transformation.

My code is as such:

src = np.array([[0, 0], [997, 102], [1000, 600], [0, 995]], np.float32)
dst = np.array([[0, 0], [997, 0], [1000, 995], [0, 995]], np.float32)
M = cv2.getPerspectiveTransform(src, dst)
warped = cv2.warpPerspective(img, M, (1000, 1000))

where the src coordinates refer to the 4 red points in the image, in clockwise order.

The dst coordinates refer to the 2 red points on the left, and the 2 blue points on the right of the image, in clockwise order.

The idea is that I want to "stretch" the image such that the 2 red points on the right correspond to the 2 blue points.

enter image description here

However, the warped image turns out to be:

enter image description here

Is there something I did wrong, or assumed wrongly about the usage of the functions?