I am trying to do a perspective correction of a tilted rectangle ( a credit card), which is tilted in all the 4 directions. I could find its four corners and the respective angles of its tilt but I cannot find the exact location of the coordinates, where it has to be projected. I am using cv2.getPerspectiveTransform to do the transformation.
I have the aspect ratio of the actual card (the non tilted one), I want such coordinates such that the original aspect ratio is preserved. I have tried using a bounding rectangle but this increases the size of the card.
Any help would be appreciated.
I have a better solution which is much easy: - The red rectangle on original image and the corners points of the rectangle are source points
- We use
cv2.getPerspectiveTransform(src, dst)
that takes source points and destination points as arguments and returns the transformation matrix which transforms any image to destination image as show in the diagram - We use this transformation matrix incv2.warpPerspective()
- As you can see results are better. You get a very nice bird view of the image
Here is the way you need to follow...
For easiness I have resized your image to smaller size,
You can refer below C++ code,