【发布时间】:2011-05-17 12:28:26
【问题描述】:
根据文档,函数cvFindContours() 返回从二进制图像输入中检索到的轮廓数。但是,当我在所有轮廓上运行循环时,检测到的轮廓数量会大大减少。
一个可能的原因是父项的子轮廓以及孔被计入函数的返回值。即便如此,这个数字与我使用的图片的合理眼睛估计不匹配。
本例中的返回值为 92,而在遍历所有轮廓时,有 15 个不同的轮廓。
代码如下:
int n = cvFindContours(img_canny_mop, mem, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
printf("No of retrieved contours = %d",n);
for (ptr = contours; ptr != NULL; ptr = ptr->h_next)
{
ext_color = CV_RGB( rand()&255, rand()&255, rand()&255 ); //randomly coloring different contours
cvDrawContours(cc_color, ptr, ext_color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
//display( cc_color, "CCs");
n_cont++;
}
cvSaveImage("CC_colors.jpg",cc_color);
printf("\nNo of contours = %d",n_cont);
图片是:
输入:http://imageshack.us/photo/my-images/811/cannymop.jpg/
随机着色的轮廓:http://imageshack.us/photo/my-images/819/cccolors.jpg/
【问题讨论】: