图像分割之最大连通域算法

CvSeq* contours = 0;   
CvMemStorage*  g_storage  = NULL;  
g_storage = cvCreateMemStorage(0);  
cvFindContours( m_image, g_storage, &contours, sizeof(CvContour), CV_RETR_EXTERNAL);
if(contours==NULL) 
return NULL;
CvSeq* contourPos;
CvRect bndRect = cvRect(0,0,0,0);
double contourArea,maxcontArea=0;
for( ; contours != 0; contours = contours->h_next )

/*bndRect = cvBoundingRect( contours, 0 ); 
contourArea=bndRect.width*bndRect.height;*/       
//与下面获取面积的方法大同小异 
contourArea = fabs(cvContourArea( contours, CV_WHOLE_SEQ )); 
if(contourArea>=maxcontArea)//提取最大轮廓 
{  
maxcontArea=contourArea;  
contourPos=contours; 
}
}

你可能感兴趣的:(算法,image,null)