I am using cvFindContour function of opencv and in it there is a parameter RETR_TYPE means retrivel type,hence I am not getting what is the difference between CV_RETR_LIST
, CV_RETR_TREE
, CV_RETR_EXTERNAL
?
RETR_TREE, reorder the contours as per the result given by OpenCV and analyze it. Again, red letters give the contour number and green letters give the hierarchy order. image. Take contour-0 : It is in hierarchy-0. Next contour in same hierarchy is contour-7.
When we use the cv2. RETR_TREE parameter, the contours are arranged in a hierarchy, with the outermost contours for each object at the top. Moving down the hierarchy, each new level of contours represents the next innermost contour for each object.
OpenCV has findContour() function that helps in extracting the contours from the image. It works best on binary images, so we should first apply thresholding techniques, Sobel edges, etc.
Look at the documentation for findContours
.
The main difference is in the hierarchy
that is returned (giving the relationship between one contour and the next).
CV_RETR_EXTERNAL
gives "outer" contours, so if you have (say) one contour enclosing another (like concentric circles), only the outermost is given.CV_RETR_LIST
gives all the contours and doesn't even bother calculating the hierarchy
-- good if you only want the contours and don't care whether one is nested inside another.CV_RETR_CCOMP
gives contours and organises them into outer and inner contours. Every contour is either the outline of an object, or the outline of an object inside another object (i.e. hole). The hierarchy
is adjusted accordingly. This can be useful if (say) you want to find all holes.CV_RETR_TREE
calculates the full hierarchy of the contours. So you can say that object1 is nested 4 levels deep within object2 and object3 is also nested 4 levels deep.From imgproc.cpp
:
//! mode of the contour retrieval algorithm enum RetrievalModes { /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for all the contours. */ RETR_EXTERNAL = 0, /** retrieves all of the contours without establishing any hierarchical relationships. */ RETR_LIST = 1, /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top level, there are external boundaries of the components. At the second level, there are boundaries of the holes. If there is another contour inside a hole of a connected component, it is still put at the top level. */ RETR_CCOMP = 2, /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/ RETR_TREE = 3, RETR_FLOODFILL = 4 //!< };
OpenCV 2.4.13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With