我附加的代码仅识别未标记的轮廓,仅在 1 和零标记的掩码上执行。我的输入蒙版图像实际上标有每个轮廓的 1,2,3,4....。例如,第一个轮廓标记为 1,第二个轮廓标记为 2,而不是所有轮廓只有 1。如何修改我的代码,以便我可以根据标记的图像分别分离每个轮廓。示例轮廓 1 是一个单独的图像,轮廓 2 是另一个单独的图像。
cvFindContours(maskImg, storage, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE, cvPoint(0, 0));
CvSeq *r;
int objectIndex = 0;
int fov = atoi(seriesName) + 1;
for(r = contours; r != NULL; r = r->h_next){
/* Save each object in separate mask file. */
/* Clear the mask object image buffer. */
cvSet(objectMaskImg, cvScalarAll(0), NULL);
/* Set the color of the external area and hole area of object. */
CvScalar externalColor = cvScalarAll(0xff);
CvScalar holeColor = cvScalarAll(0x00);
/* Recognize child contour. */
int maxLevel = -1;
/* Fill interiors */
int thinkness = CV_FILLED;
int lineType = 8; /* 8-connected */
cvDrawContours(objectMaskImg, r, externalColor, holeColor, maxLevel, thinkness, lineType, cvPoint(0,0));