CV_RETR_LIST,CV_RETR_TREE,CV_RETR_EXTERNAL之间的区别?
我正在使用opencv的cvFindContour函数,其中有一个参数RETR_TYPE意味着retrivel类型,因此我没有得到CV_RETR_LIST
, CV_RETR_TREE
, CV_RETR_EXTERNAL
之间的区别?
查看findContours
的文档 。
主要区别在于返回的hierarchy
(给出一个轮廓与下一个轮廓之间的关系)。
-
CV_RETR_EXTERNAL
给出“外部”轮廓,所以如果你有(比方说)一个包围另一个轮廓的轮廓(如同心圆),则只给出最外面的轮廓。 -
CV_RETR_LIST
给出了所有的轮廓,甚至没有计算hierarchy
– 如果你只想要轮廓而不关心是否嵌套在另一个轮廓中,那就很好了。 -
CV_RETR_CCOMP
给出轮廓并将它们组织成外轮廓和内轮廓。 每个轮廓都是对象的轮廓,或者是另一个对象(即孔) 内的对象的轮廓。hierarchy
调整。 如果(比如说)想要查找所有孔,这可能很有用。 -
CV_RETR_TREE
计算轮廓的完整层次结构。 所以你可以说object1嵌套在object2中4层深处,而object3也嵌套4层深。
来自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