提取二值图像中的最大轮廓OpenCV.docx
提取二值图像中的最大轮廓OpenCVCvPoint* points = NULL; CvMemStorage* storage = cvCreateMemStorage(0); int method = CV_CHAIN_APPROX_SIMPLE; int mode = CV_RETR_EXTERNAL; CvSeq* contours = NULL; int Nc = 0; int n_mMax = -1; Nc = cvFindContours( pImg, storage, &contours, sizeof(CvContour),mode, method); for(; contours; contours=contours->h_next) if(contours->total > n_mMax) free(points); points = NULL; n_mMax = contours->total; points = (CvPoint*)malloc(contours->total * sizeof(CvPoint); for(i=0; i<contours->total; i+) CvPoint* pt = (CvPoint*)cvGetSeqElem(contours,i); pointsi.x = pt->x; pointsi.y = pt->y; else continue;