Ask Your Question

Revision history [back]

this example program demonstrates using watershed

but you need some preprocessing like below ( add this piece of code to imageSegmentation.cpp line 26)

Mat img_gray;
cvtColor(src, img_gray, cv::COLOR_BGR2HSV);

Mat hsv[3];
split(img_gray, hsv);

img_gray = hsv[2] + hsv[1];
imshow("img_gray", img_gray);
src.setTo(Scalar(0, 0, 0), ~img_gray);

you will finally get the image below

image description

this example program demonstrates using watershed

but you need some preprocessing like below ( add this piece of code to imageSegmentation.cpp line 26)

Mat img_gray;
cvtColor(src, img_gray, cv::COLOR_BGR2HSV);

Mat hsv[3];
split(img_gray, hsv);

img_gray = hsv[2] + hsv[1];
imshow("img_gray", img_gray);
src.setTo(Scalar(0, 0, 0), ~img_gray);

this step will give you the image below

image description

and you will finally get the image below

image description

this example program demonstrates using watershed

but you need some preprocessing like below ( add this piece of code to imageSegmentation.cpp line 26)

Mat img_gray;
cvtColor(src, img_gray, cv::COLOR_BGR2HSV);

Mat hsv[3];
split(img_gray, hsv);

img_gray = hsv[2] + hsv[1];
imshow("img_gray", img_gray);
src.setTo(Scalar(0, 0, 0), ~img_gray);
    // ( this code is suitable for bright objects on gray background )

this step will give you the image below

image description

and you will finally get the image belowbelow.

image description