Watershed Error OpenCV Error: Assertion failed (src.type() == CV_8UC3 && dst.type() == CV_32SC1)

asked 2018-03-13 14:47:09 -0500

open_ranger gravatar image

I am trying to use watershed on a segmented image I made the watershed data and watershedmarker the way it required and keeps getting this error.Which part has gone wrong?

 OpenCV Error: Assertion failed (src.type() == CV_8UC3 && dst.type() == CV_32SC1) in watershed, file /home/WXH/Desktop/opencv-3.2.0/modules/imgproc/src/segmentation.cpp, line 161

the code is here

    Canny(imageCluster,edges,100,150,3, true);
    edges.convertTo(watershedData,CV_8UC3);

    watershedMarker=Mat(imageWork.rows,imageWork.cols,CV_32SC1,Scalar::all(0));
    watershedMarker.row(0)=255;
    watershedMarker.row(imageWork.rows-1)=255;
    watershedMarker.col(0)=255;
    watershedMarker.col(imageWork.cols-1)=255;


    printf("WatershedData Type is %d \n",watershedData.type());
    printf("watershedMarker Typed is %d\n",watershedMarker.type());
    watershed(watershedData,watershedMarker);
edit retag flag offensive close merge delete

Comments

watershed works on color images, so, what's the Canny doing there ?

berak gravatar imageberak ( 2018-03-14 02:54:58 -0500 )edit

the image is already segmented in grayscale and I want the watershed to flood all surronding region in white.canny will just highlight the boarder the turn all segments into black.

open_ranger gravatar imageopen_ranger ( 2018-03-14 03:40:00 -0500 )edit

wait, if the input to Canny is 1channel, the output will be too.

convertTo() only changes the depth of your image, not the number of channels.

cvtColor(.... GRAY2BGR)

berak gravatar imageberak ( 2018-03-14 03:55:06 -0500 )edit

watershed prabably not a good way to do it,but still dont understand why the data type missmatch

open_ranger gravatar imageopen_ranger ( 2018-03-14 04:25:24 -0500 )edit

ok I got it.The way convertTo() accepts a CV_8UC3 parameter got me think it convert channels too.Now I know it doent.Thanks

open_ranger gravatar imageopen_ranger ( 2018-03-14 04:29:54 -0500 )edit

common pitfall

berak gravatar imageberak ( 2018-03-14 04:32:15 -0500 )edit