Problem with Running Watershed Distance Transform in OpenCV 4.0.0

0

I'm working on an object detection project. I use OpenCV 4.0.0 and codeblocks 16.01 on Ubuntu 18.04.1. I'm testing the watershed distance transform technique using the code in this tutorial:

link

I just modified the path to my test image, so:

// Load the image
    CommandLineParser parser( argc, argv, "{@input | ../../testes/img1.jpg | input image}" );
    Mat src = imread( parser.get<String>( "@input" ) );
    if( src.empty() )
    {
        cout << "Could not open or find the image!\n" << endl;
        cout << "Usage: " << argv[0] << " <Input image>" << endl;
        return -1;
    }
    else cout << "img ok\n";

The rest of the code is exactly the same as the tutorial. However, when you run it, the following error message appears:

Doesanyonehaveanyideawhatmightbehappening?

EDIT:I'vebeentestingstepbystepalgorithm,sotheerrorhappensin:

//PerformthedistancetransformalgorithmMatdist;distanceTransform(bw,dist,DIST_L2,3);//Normalizethedistanceimageforrange={0.0,1.0}//sowecanvisualizeandthresholditnormalize(dist,dist,0,1.0,NORM_MINMAX);imshow("Distance Transform Image", dist);

The dist image after running the distanceTranform () function is totally black, and the error occurs in normalize ().

    
asked by anonymous 26.11.2018 / 04:27

1 answer

1

It seems that the imshow() function only shows images in CV_8U format. Then it was necessary to change the parameters of the normalize() function, thus:

normalize(dist, dist, 0, 255.0, NORM_MINMAX, CV_8U);

In the rest, the watershed algorithm works very well, however care needs to be taken with these details: CV_8U, CV_32S, etc.

    
26.11.2018 / 18:13