我需要将连接组件的区域保存为文本文件,并且我编写了如下代码,但我不知道我哪里出错了。谁能帮我找出问题所在?
imagefet=cvCreateImage(cvGetSize(lab),IPL_DEPTH_8U,3);
CvMemStorage* contour_storage = cvCreateMemStorage(0);
CvSeq* contours;
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.6f, 0.6f, 0, 2);
cvFindContours(lab, contour_storage, &contours, sizeof (CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
cvZero(imagefet);
FILE *file=fopen("mytxt.txt","W");
for( int ncount=1; contours != NULL; contours = contours->h_next, ncount++)
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
cvDrawContours( imagefet, contours, color, CV_RGB(255,255,255), -1, CV_FILLED, 8 ,cvPoint(0,0));
int area = abs(cvContourArea(contours, CV_WHOLE_SEQ));
fprintf(file,"%d",area);
}
fclose(file);
谢谢