检测物体轮廓。
函数声明两种:
findContours( InputOutputArray image, OutputArrayOfArrays contours,
OutputArray hierarchy, int mode,
int method, Point offset=Point());
findContours( InputOutputArray image, OutputArrayOfArrays contours,
int mode, int method, Point offset=Point());
image:输入图像。8-bit的单通道二值图像,非零的像素都会被当作1。
contours:检测到的轮廓。是一个双重向量,向量的每个元素都是一个轮廓 vector<vector<Point>> contours
hierarchy(少用):各个轮廓的继承关系 vector<Vec4i> hierarchy。向量内每一个元素的4个int型变量——hierarchy[i][0] ~hierarchy[i][3],分别表示第 i个轮廓的后一个轮廓、前一个轮廓、父轮廓、内嵌轮廓的索引编号。
mod:检测轮廓的方法。有四种方法。
—CV_RETR_EXTERNAL:只检测外轮廓。忽略轮廓内部的洞。
—CV_RETR_LIST:检测所有轮廓,但不建立继承(包含)关系。
—CV_RETR_TREE:检测所有轮廓,并且建立所有的继承(包含)关系。
—CV_RETR_CCOMP:检测所有轮廓,但是仅仅建立两层包含关系。
method:表示一条轮廓的方法。
– CV_CHAIN_APPROX_NONE:把轮廓上所有的点存储。
– CV_CHAIN_APPROX_SIMPLE: 仅保存轮廓的拐点信息
offset:Point偏移量,所有的轮廓信息相对于原始图像对应点的偏移量