34

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?

fireant
  • 14,080
  • 4
  • 39
  • 48
Milad R
  • 1,854
  • 9
  • 25
  • 36
  • 2
    possible duplicate of [how does cvFindContours work?](http://stackoverflow.com/questions/8701248/how-does-cvfindcontours-work) – pmr May 04 '12 at 17:14

2 Answers2

32

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

The paper is available here.

Yuval
  • 3,207
  • 32
  • 45
fireant
  • 14,080
  • 4
  • 39
  • 48
  • 3
    Thanks but there is a problem. I couldn't find this article on the internet(1985!), and also opencv's code is near 1700 lines and owing it is modular, then I can't find the main function that algorithm is used in that function. Can you give me a link or sth that explain the outlook of the algorithm?(Not so complicated, if the simple explanation is also available!) – Milad R May 04 '12 at 16:52
  • mh.. I edited the answer, and added a new link. Please let me know if you need something more. – fireant May 04 '12 at 16:59
  • @Milad, did that answer your question? – fireant May 07 '12 at 12:25
  • I haven't read that pdf yet. But as I look through it very quickly I think it's useful for me! But If I have a problem after read it, I will tell you. Thanks! – Milad R May 07 '12 at 18:18
  • If anyone needs a C# implementation I have one :) – ed22 Jan 05 '19 at 02:14
  • 1
    https://theailearner.com/2019/11/19/suzukis-contour-tracing-algorithm-opencv-python/ – Mr-Programs May 23 '20 at 13:13
  • Any one has python implementation of the findcontour function – acoustic python Dec 02 '20 at 11:47
5

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.

Kamyar
  • 61
  • 1
  • 4