您的位置:首页 > 运维架构

【OpenCV】cvFindContours参数详解

2016-04-15 16:33 696 查看
其参数列表为:

CvArr* image: 待提取轮廓的图像

(注意:该图像是经过二值化后的图像,二值化可以使用cvThreshold()函数)

CvMemStorage* storage: 存储空间

CvSeq** first_contour:轮廓序列

Int mode: 模式默认情况下是CV_RETR_LIST,共有4种模式:

CV_RETR_EXTERNAL: 只提取最最最外面的轮廓
CV_RETR_LIST: 把所有轮廓都保存下来,放在一张列表里,可以用下标来访问,但是不会计算轮廓之间的层次关系,也就是说并不知道轮廓之间是什么关系
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.

使用CV_RETR_CCOMP时,可以用cvDrawContours()来绘制轮廓,可以看到给外部轮廓和hole的轮廓用不同颜色,就一目了然了。

以下是cvThreshold, cvFindContours和cvDrawContours的代码:

CVAPI(double)  cvThreshold( const CvArr*  src, CvArr*  dst,
double  threshold, double  max_value,
int threshold_type );


/* Retrieves outer and optionally inner boundaries of white (non-zero) connected
components in the black (zero) background */
CVAPI(int)  cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour,
int header_size CV_DEFAULT(sizeof(CvContour)),
int mode CV_DEFAULT(CV_RETR_LIST),
int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
CvPoint offset CV_DEFAULT(cvPoint(0,0)));


/* Draws contour outlines or filled interiors on the image */
CVAPI(void)  cvDrawContours( CvArr *img, CvSeq* contour,
CvScalar external_color, CvScalar hole_color,
int max_level, int thickness CV_DEFAULT(1),
int line_type CV_DEFAULT(8),
CvPoint offset CV_DEFAULT(cvPoint(0,0)));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: