Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

I get this error:

image description

Does anyone knows what's happening?

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

I get this error:

image description

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?

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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);

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
point

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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); markers);

Mat mark = Mat::zeros(markers.size(), CV_8UC1); markers.convertTo(mark, CV_8UC1); bitwise_not(mark, mark); mark);

imshow("Markers_v2", mark); // uncomment this if you want to see how the mark waitKey(); // image looks like at that point

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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 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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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:

part: // Perform the watershed algorithm

algorithm watershed(src, markers);

Mat mark = Mat::zeros(markers.size(), CV_8UC1);
 markers.convertTo(mark, CV_8UC1);
 bitwise_not(mark, mark);

mark); imshow("Markers_v2", mark); // uncomment this if you want to see how the mark waitKey(); // image looks like at that point

point

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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: part:

// Perform the watershed algorithm watershed(src, markers);

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
point

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

click to hide/show revision 17
None

updated 2018-11-26 10:06:54 -0600

berak gravatar image

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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);

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);

-1); // Draw the background marker circle(markers, Point(5,5), 3, CV_RGB(0,255,0), -1); imshow("Markers", markers*10000);

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

point

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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); 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); -1);

// Draw the background marker circle(markers, Point(5,5), 3, CV_RGB(0,255,0), -1); imshow("Markers", markers*10000);

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

point

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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:

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

Error in Watershed Distance Transform

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/tutorial_distance_transform.html

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: 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 how the mark waitKey(); // image looks like at that point