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 Answers
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
2 Comments
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
- CV_RETR_EXTERNAL : 0
- CV_RETR_LIST : 1
- CV_RETR_CCOMP : 2
- CV_RETR_TREE : 3
METHODS
- CV_CHAIN_APPROX_NONE : 1
- CV_CHAIN_APPROX_SIMPLE : 2
- CV_CHAIN_APPROX_TC89_L1 : 3
- CV_CHAIN_APPROX_TC89_KCOS : 4