Ask Your Question

multiple contour bounding box

asked 2015-04-07 03:22:42 -0600

antithing gravatar image

updated 2020-10-23 14:09:26 -0600

Hi all. I am detecting contours in an image, and need to draw a bounding box around them all.

Right now i have a cluster of contours, and I need to run a polygon approximation that joins the external edges as a square. Picture the 'five' side of a dice, where only the dots are visible. I have each dot as a separate contour. How would I draw a square bounding box that connects the external corners and stays connecting them no matter what the rotation?

Thank you!

c++, visual studio.

edit retag flag offensive close merge delete



you could join the boundingRects with the |operator:

Rect big = r1 | r2 | r3 ..
berak gravatar imageberak ( 2015-04-07 04:05:52 -0600 )edit

Thanks! That works. BUT, As I have contours on the corners and contours in the middle, is there a way to make sure i am using the outermost edge?

Also, is the code different with a Rotatedrect? I can't get that one to work. thanks again!

antithing gravatar imageantithing ( 2015-04-07 06:01:07 -0600 )edit

no such operators for RotatedRect, unfortunately.

berak gravatar imageberak ( 2015-04-07 06:28:08 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-04-09 08:07:54 -0600

antithing gravatar image

updated 2015-04-09 08:08:06 -0600

sorted. I found the contours, used cv::moments to get the mid-point of each contour, stored those in a vector or points and used:

         calculatedRect = minAreaRect(storedpoints);

to get the bounding box.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-07 03:22:42 -0600

Seen: 4,360 times

Last updated: Apr 09 '15