1

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?

ispiro
  • 151
  • If you know which corner is which, you can draw vectors along the edges of the original square and square on your image with the same length ratios. Then by summing the vectors you will arrive at the expected point https://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Vector_addition.svg/445px-Vector_addition.svg.png – Aleksejs Fomins Aug 23 '18 at 12:16
  • @AleksejsFomins Take a look at this image of the reflecting pool. Obviously the middle of the right or left sides on the projection (-the picture) are not the mid points in the pool itself. – ispiro Aug 23 '18 at 12:20
  • Then you have a combination of an affine transformation and a perspective transformation. Affine transformations can be undone by figuring out a linear matrix that did them from the corner coordinates. It is more tricky for perspective transformations. But perhaps, if your actual square is not that big, the depth does not matter? – Aleksejs Fomins Aug 23 '18 at 12:38

2 Answers2

1

This is not a complete solution but for all practical purposes it should be sufficient. Let $A'B'C'D'$ be a square in the space and $ABCD$ be its perspective projection on the plane. Let $E$ be the intersection of $AB$ And $CD$. Let $M$ and $N$ be the images of the midpoints of $A'D'$ and $B'C'$. Let $G$ be the intersection of $AC$ and $BD$. Then $M,N,G$ and $E$ are collinear. This is because on the square the line passing through the midpoints of two opposite sides goes through the center of the square and is parallel to the other two sides. Parallel lines in perspective geometry have a vanishing point (or stay parallel if the vanishing point is infinity). We can locate $G$ and $E$ on the image. Draw a line through them to locate $M$ and $N$. Then $MNCD$ is the image of a rectangle. In a similar fashion we can locate the midpoints of its sides. Continuing this way we can locate all the points with coordinates $m/2^n$ on the four sides of the figure. By connecting these points, we obtain a grid inside the figure where each subfigure is the image of a rectangle. We can locate the center of each subfigure by intersecting its diagonals. This gives a mesh of points inside the figure corresponding to the points inside the square. For higher precision, increase $n$ the number of subdivisions of the sides.

Marco
  • 2,733
  • 6
  • 15
  • Let E be the intersection of AB And CD. - Did you mean the semi parallel top and bottom lines? – ispiro Aug 23 '18 at 13:43
  • Yes, but if they happen to be parallel, then that intersection is at infinity and connecting $G$ to $E$ would mean draw a line through $G$ parallel to those two sides. – Marco Aug 23 '18 at 13:45
1

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.

amd
  • 53,693