using namespace cv;
using namespace std;
+void help()
+{
+ cout << "\nThis program demonstrates the famous watershed segmentation algorithm in OpenCV: watershed()\n"
+ "Usage:\n"
+ "./watershed [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";
+}
Mat markerMask, img;
Point prevPt(-1, -1);
}
}
-
int main( int argc, char** argv )
{
char* filename = argc >= 2 ? argv[1] : (char*)"fruits.jpg";
if( img0.empty() )
{
- cout << "Usage: watershed <image_name>\n";
+ cout << "Couldn'g open image " << filename << ". Usage: watershed <image_name>\n";
return 0;
}
-
- cout << "Hot keys: \n"
- "\tESC - quit the program\n"
- "\tr - restore the original image\n"
- "\tw or SPACE - run watershed algorithm\n"
- "\t\t(before running it, roughly mark the areas on the image)\n"
- "\t (before that, roughly outline several markers on the image)\n";
-
+ help();
namedWindow( "image", 1 );
img0.copyTo(img);