我的附加代码仅识别未标记的轮廓,仅在1和零标记的掩码上执行。我的输入掩码图像实际上标有每个轮廓的1,2,3,4 ....例如,第一个轮廓标记为1,第二个轮廓标记为2,所有轮廓的标记仅为1。如何修改我的代码,以便我可以根据标记的图像分别分离每个轮廓。例如,contour1是一个单独的图像,contour2是另一个单独的图像。
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));
答案 0 :(得分:0)
您可以在面具和FindContours返回的轮廓之间使用逻辑AND
吗?或许我不太明白你在做什么。