Reputation: 450
Hi I am working with javacv and seriously I dont have any idea what I am stuck into. I somehow managed to write a running code but I dont know why the result is not according to the example given on this link under the heading The watershed algorithm. Example and here is my code with the same image using in the example (Image of the road). Here is my code the image w.jpg is the image without white markers and the w_markers.jpg is with those markers. The result I am getting is just w.jpg nothing changed not even a bit.
public static void doWatershed(){
IplImage sample = null, marker= null;
sample = cvLoadImage("C:\\Users\\Areeb\\Desktop\\w.jpg");
marker = cvLoadImage("C:\\Users\\Areeb\\Desktop\\w_markers.jpg");
IplImage newImage = cvCreateImage(cvGetSize(sample), IPL_DEPTH_8U, 3);
cvCopy(sample, newImage);
IplImage GrayImage = cvCreateImage(cvGetSize(sample), IPL_DEPTH_8U, 1);
cvCvtColor(sample, GrayImage, CV_BGR2GRAY);
//ShowImage(GrayImage, "GrayImage", 512);
IplImage BWImage = cvCreateImage(cvGetSize(GrayImage), IPL_DEPTH_8U, 1);
cvThreshold(GrayImage, BWImage, 127, 255, CV_THRESH_BINARY);
IplImage fg = cvCreateImage(cvGetSize(GrayImage), IPL_DEPTH_8U, 1);
cvErode(GrayImage, fg, null, 2);
IplImage bg = cvCreateImage(cvGetSize(GrayImage), IPL_DEPTH_8U, 1);
cvDilate(GrayImage, bg, null, 3);
cvThreshold(bg, bg, 100, 255, CV_THRESH_BINARY_INV);
IplImage markerscpp = cvCreateImage(cvGetSize(GrayImage), IPL_DEPTH_8U, 1);
cvAdd(fg, bg, markerscpp,null);
ShowImage(markerscpp, "markers");
IplImage grey32 = cvCreateImage(cvGetSize(markerscpp), IPL_DEPTH_32S, 1);
cvConvert(markerscpp, grey32);
System.out.print(marker.sizeof()+" : "+GrayImage.sizeof());
cvWatershed(newImage, grey32);
//ShowImage(grey32, "Grey");
ShowImage(newImage, "Watershed");
}
Thanks for the help in advance.
Upvotes: 0
Views: 368
Reputation:
After converting your image to greyscale. Take mean of the image and then convert it to binary. The segmentation will take place and will be visible to grey image which is commented in the second last line.
Upvotes: 1