我正在尝试查找图像小区域内存在的连通组件(如果有)。但是cvFindContours()函数将明显分离的组件分组为一个单一组件,从而使进一步计算不正确。
如何获取区域内的单独组件?(将不同颜色的组件作为函数检测到的内容)。
以下是代码:
IplImage* cc_img = cvCreateImage( cvGetSize(src), src->depth, 3 );
cvSetZero(cc_img);
CvScalar(ext_color);
CvMemStorage *mem;
mem = cvCreateMemStorage(0);
CvSeq *contours = 0;
CvSeq *ptr;
int n_cont = 0;
int n = cvFindContours( src, mem, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
for (ptr = contours; ptr != NULL; ptr = ptr->h_next)
{
n_cont++;
ext_color = CV_RGB( rand()&255, rand()&255, rand()&255 ); //randomly coloring different contours
cvDrawContours(cc_img, ptr, ext_color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
}
“CEL”被认为是单个组件!
CvFindContours
这样的方法。 - AruniRC