OpenCV algorithm of contours searching and creation of bounding rectagle

991 views Asked by At

Hi to the whole programmers society!

It has become habitual to me to get acknowledgement of every algorithm I employ in projects. And not long ago I implemented OpenCV library methods to detect contours within input frame as well as to draw bounding rectangle around detected object. So I came up with question: what algorithm is actually used by OpenCV when calling appropriate methods? (I mean exacty cv2.findContours and cv2.boundingRect methods)

Thank you in advance.

1

There are 1 answers

0
Daiver On BEST ANSWER

According to OpenCV documentation findContours uses "Suzuki, S. and Abe, K., Topological Structural Analysis of Digitized Binary Images by Border Following"

The function retrieves contours from the binary image using the algorithm [Suzuki85].

I didn't find description of boundingRect algorithm but found this file in opencv repo

7.a. Straight Bounding Rectangle It is a straight rectangle, it doesn't consider the rotation of the object. So area of the bounding rectangle won't be minimum. It is found by the function cv2.boundingRect(). Let (x,y) be the top-left coordinate of the rectangle and (w,h) be its width and height. @code{.py} x,y,w,h = cv2.boundingRect(cnt) cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) @endcode

So it seems that boundingRect just finds minimum and maximum coordinates of input set of points

PS Sorry for my poor English