画像分割の最大連通域アルゴリズム


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; 
}
}