0
votes

I think,I understood well the function "cv2.findContours(image, mode, method). But I got this thing contours,hierarchy = cv2.findContours(thresh,2,1) in one of the documents of opencv. I am not getting what is the meaning of 2,1 here and why have they been used. Someone please explain it.

2
They are flags for contour retrieval mode and contour approximation method. Basically int values representing which method/mode to be used. Please read the documentation - Rick M.

2 Answers

1
votes
void cv::findContours   (   InputOutputArray    image,
OutputArrayOfArrays     contours,
OutputArray     hierarchy,
int     mode,
int     method,
Point   offset = Point() 
)       

Finds contours in a binary image.

The function retrieves contours from the binary image using the algorithm [132] . The contours are a useful tool for shape analysis and object detection and recognition. See squares.c in the OpenCV sample directory.

Some doc could help you: http://docs.opencv.org/trunk/d9/d8b/tutorial_py_contours_hierarchy.html

1
votes

The mode and method parameter of findContours() are enum with integer values. One can use either the keywords or the integer values assigned to it. This detail can be viewed as an intellisense in visual studio when opencv is included in a project.

Below are the associated values with each enum.

MODES

  1. CV_RETR_EXTERNAL : 0
  2. CV_RETR_LIST : 1
  3. CV_RETR_CCOMP : 2
  4. CV_RETR_TREE : 3

METHODS

  1. CV_CHAIN_APPROX_NONE : 1
  2. CV_CHAIN_APPROX_SIMPLE : 2
  3. CV_CHAIN_APPROX_TC89_L1 : 3
  4. CV_CHAIN_APPROX_TC89_KCOS : 4