CvSeq* contour = NULL;
double minarea = 100.0;
double tmparea = 0.0;
CFileDialog dlg(true);
if (dlg.DoModal()==IDOK)
{
CvMemStorage* storage = cvCreateMemStorage();
IplImage* img_src= cvLoadImage(dlg.GetPathName(),CV_LOAD_IMAGE_ANYCOLOR);
IplImage* img_Clone=cvCloneImage(img_src);
//访问二值图像每个点的值
uchar *pp;
//显示原始图像
cvNamedWindow("img_src",CV_WINDOW_AUTOSIZE);
cvShowImage("img_src", img_src);
IplImage* img_dst = cvCreateImage(cvGetSize(img_src),IPL_DEPTH_8U,);
//------------搜索二值图中的轮廓,并从轮廓树中删除面积小于某个阈值minarea的轮廓-------------//
CvScalar color = cvScalar(,,);//CV_RGB(128,0,0);
CvContourScanner scanner = NULL;
scanner = cvStartFindContours(img_src,storage,sizeof(CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE,cvPoint(,));
//开始遍历轮廓树
CvRect rect;
while (contour=cvFindNextContour(scanner))
{
tmparea = fabs(cvContourArea(contour));
rect = cvBoundingRect(contour,);
if (tmparea < minarea/*||tmparea>4900*/)
{
//当连通域的中心点为黑色时,而且面积较小则用白色进行填充
pp=(uchar*)(img_Clone->imageData + img_Clone->widthStep*(rect.y+rect.height/)+rect.x+rect.width/);
if (pp[]==)
{
for(int y = rect.y;y<rect.y+rect.height;y++)
{
for(int x =rect.x;x<rect.x+rect.width;x++)
{
pp=(uchar*)(img_Clone->imageData + img_Clone->widthStep*y+x);
if (pp[]==)
{
pp[]=;
}
}
}
}
}
}
cvSaveImage("c://temp//aav.bmp",img_Clone);