Given the 4 corners of two QR codes on a photographed sheet of paper, can we get a deskewed rectangular image? I made a photo of 2 sheets of paper with a phone camera, each of them cropped at the:


(x1, y1) top left corner of top QR code
(x2, y2) bottom right corner of bottom QR code


I hoped that the x, y coordinate of checkboxes would be nearly the same. In fact it's not, because of the angle of the camera, skewness, etc.

Question: How to have a better deskewing by using 8 corners:


the 4 corners of top QR code  (detected automatically by this method): (x1, y1), ..., (x4, y4)
the 4 corners of bottom QR code: (x5, y5), ..., (x8, y8)


?




Note: links of the 2 images: https://i.stack.imgur.com/SR8hz.jpg and https://i.stack.imgur.com/XsxrT.jpg
The solution is to use an "homography" / aka "projective transformation" (see this PDF, page 16).

Here is a working code showing how to do it with Python + OpenCV.