Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the algorithm that opencv uses for finding contours?

I need to use cv::FindContours() in a program and I have to know the algorithm behind that.

What algorithm does openCV use to find contours?

How does it work?

like image 751
Milad R Avatar asked May 03 '12 08:05

Milad R


People also ask

How do you find the contour area in OpenCV?

It is found by the function cv. Let (x,y) be the top-left coordinate of the rectangle and (w,h) be its width and height.

How does OpenCV detect closed contours?

Just use findContours() in your image, then decide whether the contour is closed or not by examining the hierarchy passed to the findContours() function.

Which algorithm is used to constructing an approximate contour curve?

Contour approximation is an algorithm for reducing the number of points in a curve with a reduced set of points — thus, an approximation. This algorithm is commonly known as the Ramer-Douglas-Peucker algorithm, or simply: the split-and-merge algorithm.


2 Answers

If you read the documentation it is mentioned this function implements the algorithm of:

Suzuki, S. and Abe, K., Topological Structural Analysis of Digitized Binary Images by Border Following. CVGIP 30 1, pp 32-46 (1985)

OpenCV is open source if you want to see how this is implemented just need to read the code: https://github.com/opencv/opencv/blob/master/modules/imgproc/src/contours.cpp#L1655

One of the answers to this question has the link to the paper in question, that link is dead and the paper is behind a pay wall, perhaps google can help with finding a free copy.

like image 159
fireant Avatar answered Oct 12 '22 14:10

fireant


As of Sep. 2018, the paper is available through Google Scholar. Nonetheless, here is the abstract in case the paper is taken down:

Two border following algorithms are proposed for the topological analysis of digitized binary images. The first one determines the surroundness relations among the borders of a binary image. Since the outer borders and the hole borders have a one-to-one correspondence to the connected components of l-pixels and to the holes, respectively, the proposed algorithm yields a representation of a binary image, from which one can extract some sort of features without reconstructing the image. The second algorithm, which is a modified version of the first, follows only the outermost borders (i.e., the outer borders which are not surrounded by holes). These algorithms can be effectively used in component counting, shrinking, and topological structural analysis of binary images, when a sequential digital computer is used.

like image 20
Raymak Avatar answered Oct 12 '22 13:10

Raymak