OpenCV中如何对二值图保证找到所有的外轮廓?
//pImage已创建有图像
CvSeq *cont = NULL;
CvMemStorage *stor = NULL;
stor = cvCreateMemStorage(0);
cont = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint), stor);
IplImage *pTempImage = cvCreateImage(cvSize(pImage->width, pImage->height), IPL_DEPTH_8U, 1);
//清空
cvZero(pTempImage);
//转为灰度图
cvCvtColor(pImage, pTempImage, CV_BGR2GRAY);
//二值化
cvThreshold(pTempImage, pTempImage, 23, 255.0, CV_THRESH_BINARY);
//得到外轮廓
const unsigned long ulContourCount = cvFindContours(pTempImage,stor,&cont,sizeof(CvContour),CV_RETR_EXTERNAL,CV_CHA IN_APPROX_SIMPLE, cvPoint(0, 0));
CvRect ContourRect;
for(int i=0; cont && i<ulContourCount; cont = cont->h_next, i++)
{
//轮廓白色像素总数
ContourPixelCount = u32(fabs(cvContourArea(cont, CV_WHOLE_SEQ)));
//提取外轮廓
ContourRect = cvBoundingRect(cont);
}
//略...
//对白色块状的像素块很容易找出来,但对不规则条状的白色像素块却找不出来?