0

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.

sonu thomas
  • 2,161
  • 4
  • 24
  • 38
  • 2
    you **must not** use opencv's deprecated c-api, it's only around for legacy/maintenance reasons. no new code should be written using that.. – berak Jun 11 '15 at 08:18
  • 1
    @berak I am using this for maintenance reason of my work. Kindly comment on the problem – sonu thomas Jun 11 '15 at 08:21
  • again, the only valid advice is to rewrite the whole thing using c++ – berak Jun 11 '15 at 08:31
  • again, kindly comment on the problem. – sonu thomas Jun 11 '15 at 08:35
  • @berak and sonu: this is a recent discussion on Meta: [where does SO stand on answers versus alternatives?](http://meta.stackoverflow.com/q/296613/2564301). Comment from Hans Passant: "SO is not a personal helpdesk, the Q+A needs to be useful to more than one programmer and that includes the consideration for alternatives". – Jongware Jun 11 '15 at 08:41

1 Answers1

2

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.

beaker
  • 16,331
  • 3
  • 32
  • 49