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.sstatic.net/SR8hz.jpg and https://i.sstatic.net/XsxrT.jpg

  • $\begingroup$ You want to find a "homography", or a linear transform that takes a point in one plane (image) and maps it onto another. Assuming the paper is not bent in anyway, we can assume that all points on the paper are coplanar. You can compute the homography between 4 corresponding points, (ie. all four corners of the top left QR code), and use that to find the corresponding point in one image, given the other (homographies are invertible). Here's how to compute the homography $\endgroup$
    – Carpetfizz
    May 20, 2018 at 22:40

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.