# How to detect concentric squares?

I have vector of approximated 4-point closed contours. How I can determine that some of them are concentric?

edit retag close merge delete

Sort by ยป oldest newest most voted

The way to go I thing is using minAreaRect function that returns a RotatedRect that has a centre. Based on the distance between the centres, you can define an error of "concentricity" of the two or more rectangles.

more

I througth about it. But if view angle is too big squares turn into quads and can not be decribed by RotatedRect. But I'll try and let you know.

( 2014-09-22 08:03:47 -0500 )edit

you have also fitEllipse, but it returns RotatedRect too. (Anyway, what do you mean by quad?)

( 2014-09-22 08:20:42 -0500 )edit

Worked well for me! To compare whether two contours are nested, and to find the biggest one:

• minAreaRect(); for both contours
• pointPolygonTest() for each contour and the other contour's center
• If the signs of both pointPolygonTest() calls are positive, they are concentric
• the outermost contour has the largest area, compute with contourArea()
( 2017-04-12 19:49:08 -0500 )edit

Official site

GitHub

Wiki

Documentation