0

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.

1
  • 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 Commented Jun 9, 2017 at 11:48

2 Answers 2

1
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

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry to say but I didn't get how can I represent mode and method in form of integers?
Int values are representing which method/mode to be used. Have you read the documentation? To use them I will be doing trial-error to see what do they represent, but, thats my choice.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.