openCV watershed

i’m trying to implement this watershed algorithm in opencv (c flavour) in order to do some segmenting on a depth image but am stumped re: the last step.
does anybody have any idea what the equivalent function is for cv.connectedComponents()?
thanks++ for any tips

Hello @mantissa . The current openCV version in OF is 4.0.1

The function you are looking for is included

At the bottom of the page an example is linked, maybe it can be helpful to you?

@mantissa I think you will need to use the C++ version for that function.

When I am using the C++ opencv api in ofxOpenCv I do something like this:

    //using this approach -
    cv::Mat inputChar = cv::cvarrToMat(myofxCvImage.getCvImage());
    cv::Mat inputFloat;
    cv::Mat kernel = cv::Mat::ones(mErodeX, mErodeY, CV_8UC1);
    erode(inputChar, inputChar, kernel);
    cv::distanceTransform(inputChar, inputFloat, CV_DIST_L2, 5);
    cv::normalize(inputFloat, inputFloat, 0, 255., cv::NORM_MINMAX);
    inputFloat.convertTo(inputChar, CV_8UC1);
    erode(inputChar, inputChar, kernel);

    //now convert back to old C style ofxOpenCv friendly image 
    IplImage dumb = cvIplImage(inputChar);
    cvCopy(&dumb, myofxCvImage.getCvImage());
    myofxCvImage.flagImageChanged(); // just incase 

I think something like above will work the same for you.
I am guessing cv::connectedComponents will be what you are after?

Btw the code above does something similar, create interior blobs from shapes that are touching.
You might need to play with mErodeX, and mErodeY ( as ofParameters ) but it should do a similar thing as the article. Note: we do a blur and threshold with ofxOpenCv after the steps above to shrink the interior blob.