Geometry – How to Calculate a Location on a Square’s Projection on a Plane

geometryprojective-geometry

I have the projection of a square on a plane. I know it's four corners' coordinates on said plane. (This is from a picture of a square taken by a camera at an unknown relation to the square.)

I now need to be able to locate any point on the square (in square coordinates) on the plane. (I assume that the center of the square (point 0.5/0.5) is "located" on the plane at the intersection of the diagonals, but I need to be able to locate any arbitrary point.)

I first thought of calculating the percent of the distance on the sides and then finding their intersection. For example, to find point 0.2,0.6 I would find the 0.2 point on the top and bottom sides, create a line between them, and do the same for point 0.6 on the left and right sides. Then find the intersection of these 2 lines. But this would only be an approximation, because the closer side of the square to the camera would have more square-distance per projection-distance.

So how do I achieve the correct calculation?

Best Answer

The scene plane in which the square lies and the image plane are related by a planar projective transformation. This answer explains a way to compute the transformation. To use that method, you need to choose a coordinate system for the square’s plane. Your idea of treating it as a unit square by computing the fractions of the distances along both dimensions does that, and makes the matrix $A$ for the source part of the map particularly easy to compute: solving $$\begin{pmatrix}0&1&0\\0&0&1\\1&1&1\end{pmatrix} \begin{pmatrix}\lambda\\\mu\\\tau\end{pmatrix} = \begin{pmatrix}1\\1\\1\end{pmatrix}$$ gives $(-1,1,1)^T$, and so $$A^{-1} = \begin{pmatrix}1&1&-1\\1&0&0\\0&1&0\end{pmatrix}.$$ Take care to put the corresponding vertices of the image quadrilateral in the correct order when computing $B$. Note that this doesn’t require knowing anything about the perspective projection itself: you just need the vertex coordinates in the image.

Related Question