I am working on a small project that “scans” sheets of paper using a camera (in particular, an iPhone camera).
Workflow:
Allows users to take pictures of sheets of paper and then detect corners / contours, so I know the 4 corner points of the original sheet of paper in the photo. Then, it is easy to invert the perspective transformation of the camera to obtain a “flat” image of the photographed sheet of paper.
However, my question is: how do I maintain or even calculate the correct (original) aspect ratio?

As you can see above, I have the coordinates for the corner points, and I also know how to build a matrix to map the upper left corner to the point (0,0), upper right corner (width, 0), lower right corner (width, height) and lower left corner (0, height).
Now the question is:. How to get the correct aspect ratio of width and height on a piece of paper. I'm pretty sure that I can figure it out with the help of angles to determine the transformation of perspective, but I'm stuck in finding the right formula. I also have a hunch that I would also need the focal length of the camera, but it would be great not to need it.
Any ideas would be appreciated.
source share