我编写了一段代码,用于查找连接的组件并使用 cvPutText 用字母“R”标记连接的组件。现在我需要根据连接组件的数量打印 1,2,3,....等数字,而不是 Letter'R'。之后我需要找到区域并将连接组件的区域打印为文本。谁能帮我这个?
这是我的代码:
imagelab=cvCreateImage(cvGetSize(mor),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(mor, contour_storage, &contours, sizeof (CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
cvZero(imagelab);
for( ; contours != NULL; contours = contours->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
cvDrawContours( imagelab, contours, color, CV_RGB(255,255,255), -1, CV_FILLED, 8 ,cvPoint(0,0));
CvRect iconBox = cvBoundingRect(contours, 0);
CvPoint center = cvPoint(iconBox.x + (iconBox.width / 2), iconBox.y + (iconBox.height / 2));
int area = abs(cvContourArea(contours, CV_WHOLE_SEQ));
cvPutText(imagelab,"R", center, &font, CV_RGB(255, 255, 255));
}
谢谢。