# Are four projected lines from a square?

I've detected a few lines in an image. Four of them are the edges of a square depicted in the image. The projective transformation of the camera has of course been applied to all the lines, making it impossible to use regular metrics such as straight angles and so on.

If I draw four randomly chosen lines from the attached image. Is there any way to decide whether those lines are the edges of a square? • Every set of four lines apparently can form a square in two different ways and also an infinite number of rectangles. In practical applications there must be some way to rule out ones that mathematically involve viewing from near infinity or at an extremely wide angle. For example when a 1x1 square maps to a 2x1 rectangle that's mathematically possible but won't happen in practical applications. This is where I'm stuck though. – hippietrail Aug 24 '17 at 2:38

Any set of four lines can represent the image of a square under a projective transform: Suppose your lines are $g_1$ through $g_4$. Let $P$ be the intersection of $g_1$ with $g_3$ and $Q$ be the intersection of $g_2$ with $g_4$. Then the line $\ell$ connecting $P$ and $Q$ will serve as the line at infinity. Any transformation which maps that line back to infinity will turn your quadrilateral into a parallelogram, a shear will turn that into a rectangle, and an anisotropic scale that into a square. All of the operations can be combined into a single projective transformation.