Error in Watershed Distance Transform [closed]
I'm trying to execute image segmentation with distance transform and watershed algorithm. I've used GrabCut to eliminate the background. After several tests, I found the error in this part:
// Perform the distance transform algorithm
Mat dist;
distanceTransform(bw, dist, DIST_L2, 3);
// Normalize the distance image for range = {0.0, 1.0}
// so we can visualize and threshold it
normalize(dist, dist, 0, 1.0, NORM_MINMAX);
imshow("Distance Transform Image", dist);
I'm using Codeblocks, Ubuntu 18.04 and OpenCV 4.0.0.
The little part of the code above is from this tutorial: https://docs.opencv.org/4.0.0/d2/dbd/...
I get this error:
terminate called after throwing an instance of ‘cv::Exception'
what(): OPenCV(4.0.0) /home/nicolas/opencv-4.0.0/sources/modules/highgui/src/window_gtk.cpp:146: error: (-215:Assertion failed) dst.data == widget->original_image->data.ptr in function ‘cvlmageWidgetSetImage'
Aborted (core dumped)Process returned 134 (0x86) execution time : 3.122 s Press ENTER ti continue.
Does anyone knows what's happening?
EDIT 1: Berak's answer solved the problem above, thanks berak! But after I've got another error in this part:
// Create the marker image for the watershed algorithm Mat markers = Mat::zeros(dist.size(), CV_8U);//CV_32SC1);
// Draw the foreground markers for (size_t i = 0; i < contours.size(); i++) drawContours(markers, contours, static_cast<int>(i), Scalar::all(static_cast<int>(i)+1), -1);
// Draw the background marker circle(markers, Point(5,5), 3, CV_RGB(0,255,0), -1); imshow("Markers", markers*10000);
I replaced CV_32SC1 with CV_8U and it worked, but I don't know if it's the right solution. After I got another error in this part:
// Perform the watershed algorithm watershed(src, markers); Mat mark = Mat::zeros(markers.size(), CV_8UC1); markers.convertTo(mark, CV_8UC1); bitwise_not(mark, mark); imshow("Markers_v2", mark); // uncomment this if you want to see how the mark waitKey(); // image looks like at that point
would you be so nice, and replace the error screenshot with a TEXT version, so it can be quoted / indexed properly ? thank you !
Yes, sure! It's ok the way I did it?
sure, thanks a lot !