Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between CV_RETR_LIST,CV_RETR_TREE,CV_RETR_EXTERNAL?

Tags:

c++

c

opencv

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?

like image 853
ATG Avatar asked Jan 12 '12 05:01

ATG


People also ask

What is Retr_tree?

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.

What is OpenCV hierarchy?

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.

What is cv2 Findcontours?

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.


2 Answers

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.
like image 132
mathematical.coffee Avatar answered Oct 08 '22 19:10

mathematical.coffee


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

like image 34
tomfriwel Avatar answered Oct 08 '22 19:10

tomfriwel