#include <cstdio>
#include <iostream>
static void help(char** argv)
{
cout << "\nThis program demonstrates the famous watershed segmentation algorithm in OpenCV: watershed()\n"
"Usage:\n" << argv[0] <<" [image_name -- default is fruits.jpg]\n" << endl;
cout << "Hot keys: \n"
"\tESC - quit the program\n"
"\tr - restore the original image\n"
"\tw or SPACE - run watershed segmentation algorithm\n"
"\t\t(before running it, *roughly* mark the areas to segment on the image)\n"
"\t (before that, roughly outline several markers on the image)\n";
}
static void onMouse( int event, int x, int y, int flags, void* )
{
if( x < 0 || x >= img.
cols || y < 0 || y >= img.
rows )
return;
{
prevPt = pt;
prevPt = pt;
}
}
int main( int argc, char** argv )
{
{
help(argv);
return 0;
}
{
cout << "Couldn't open image ";
help(argv);
return 0;
}
help(argv);
for(;;)
{
if( c == 27 )
break;
if( c == 'r' )
{
}
if( c == 'w' || c == ' ' )
{
int i, j, compCount = 0;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
if( contours.empty() )
continue;
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0], compCount++ )
if( compCount == 0 )
continue;
vector<Vec3b> colorTab;
for( i = 0; i < compCount; i++ )
{
}
for( i = 0; i < markers.rows; i++ )
for( j = 0; j < markers.cols; j++ )
{
int index = markers.at<
int>(i,j);
if( index == -1 )
else if( index <= 0 || index > compCount )
else
wshed.at<
Vec3b>(i,j) = colorTab[index - 1];
}
wshed = wshed*0.5 + imgGray*0.5;
imshow(
"watershed transform", wshed );
}
}
return 0;
}