0

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)

357865
  • 13
  • 4
  • 2
    This is just finding the 2d projective transform that maps your 4 distorted corners to the target rectangle you wish, and then apply it to your image. Many libraries have that already implemented. – Julien Jun 21 '23 at 02:02
  • Indeed, map the four corners to their new position, other points of the image are mapped according to linear interpolation between those four points. As you don’t have z positions, you cannot compute a rotation, but if you could it would be unnecessary and overly complex. – Cris Luengo Jun 21 '23 at 02:14
  • Does this answer your question? [reverse or invertible ndimage.map\_coordinates mapping based on planar homography](https://stackoverflow.com/questions/76031781/reverse-or-invertible-ndimage-map-coordinates-mapping-based-on-planar-homography) – Christoph Rackwitz Jun 21 '23 at 07:01
  • "projective transform" can also be callled "homography". since the original distortion is perspective, a lesser transformation (2d linear interpolation) will introduce its own distortion. --the angles are implied by the corner positions. you can't count the angles as information. that information is already in the corner positions. – Christoph Rackwitz Jun 21 '23 at 07:02

0 Answers0