Ask Your Question

How to detect concentric squares?

asked 2014-09-22 06:04:08 -0500

Victor1234 gravatar image

updated 2014-09-22 07:29:26 -0500

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-09-22 07:47:27 -0500

thdrksdfthmn gravatar image

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.

edit flag offensive delete link 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.

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

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

thdrksdfthmn gravatar imagethdrksdfthmn ( 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()
pibbs gravatar imagepibbs ( 2017-04-12 19:49:08 -0500 )edit

Question Tools


Asked: 2014-09-22 06:04:08 -0500

Seen: 575 times

Last updated: Sep 22 '14