CvConnectedComp.contour is NULL with cvFloodFill

275 views Asked by At

I am trying to use CvConnectedComp which is an output from cvFloodFill.

CvConnectedComp comp;
cvFloodFill(imgInput,seedPoint,
        cvScalarAll(0),cvScalarAll(.1),cvScalarAll(1.),
        &comp,CV_FLOODFILL_MASK_ONLY,imgMask);

I am able to use comp.rect for drawing the component, but comp.contour is NULL.I want to use it for further processing. I tried without mask also, but still it is same result.

Any idea will be appreciated.

1

There are 1 answers

0
beaker On

Note: The deprecated OpenCV C API should only be used for the support of legacy code. New code should use the C++ API.

Looking at the code for OpenCV 3.0.0, cvFloodFill does not populate comp.contour; the only members it sets are .rect, .area, and .value. I don't know if it was always this way, but here's what's happening:

First, look at the signature for the C++ cv::floodFill:

int floodFill(InputOutputArray image, InputOutputArray mask, Point seedPoint, 
              Scalar newVal, Rect* rect=0, Scalar loDiff=Scalar(), 
              Scalar upDiff=Scalar(), int flags=4 )

Notice that there is no connected component structure here, only a Rect. The return value is the area of the region that is floodfilled.

This is the method that is called by cvFloodFill. The code passes &comp->rect to the C++ method where it is populated, uses the return value for comp->area an copies newVal into comp->value.