CV_RETR_LIST,CV_RETR_TREE,CV_RETR_EXTERNAL之间的差异?

ATG*_*ATG 19 c c++ opencv

我使用的OpenCV cvFindContour功能,它有一个参数RETR_TYPE意味着retrivel类型,所以我没有得到之间有什么区别CV_RETR_LIST,CV_RETR_TREE,CV_RETR_EXTERNAL

mat*_*fee 28

查看文档findContours.

主要区别在于hierarchy返回(给出一个轮廓和下一个轮廓之间的关系).

  • CV_RETR_EXTERNAL 给出"外部"轮廓,所以如果你有一个轮廓包围另一个轮廓(如同心圆),则只给出最外面的轮廓.
  • CV_RETR_LIST给出所有的轮廓,甚至不打算计算hierarchy- 好的,如果你只想要轮廓而不关心一个是否嵌套在另一个内.
  • CV_RETR_CCOMP给出轮廓并将它们组织成外部和内部轮廓.每个轮廓都是对象的轮廓,或者是另一个对象(即孔)的对象的轮廓.将hierarchy作相应调整.如果(比如说)要查找所有孔,这可能很有用.
  • CV_RETR_TREE计算轮廓的完整层次结构.所以你可以说object1嵌套在object2中4层深处,而object3也嵌套4层深.


tom*_*wel 5

来自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 //!<
};
Run Code Online (Sandbox Code Playgroud)

OpenCV 2.4.13