I am working on a project where I need to 'square up' a piece of paper in a photo, so it appears to have no rotation in 3d space. I have already written an algorithm to find the corners of the piece of paper in the image, and the angles of the sides. However, I have no idea how to find the amount the image needs to be rotated to 'be square'.
I have looked into reversing the formula(s) used to rotate 2d objects in 3d space, but all the results I can find need the z-coordinates of the points, which I don't have, since I am using a 2d photograph.
Does anyone know how to find the 3d rotation of a 2d rectangle using just the corners and angles? Any help would be appreciated.
(any code in python if possible)