revamped
authorGary Bradski <no@email>
Sat, 4 Dec 2010 08:31:05 +0000 (08:31 +0000)
committerGary Bradski <no@email>
Sat, 4 Dec 2010 08:31:05 +0000 (08:31 +0000)
samples/cpp/watershed.cpp

index 2b311d2..955eaf2 100644 (file)
@@ -7,6 +7,20 @@
 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);
 
@@ -30,7 +44,6 @@ void onMouse( int event, int x, int y, int flags, void* )
     }
 }
 
-
 int main( int argc, char** argv )
 {
     char* filename = argc >= 2 ? argv[1] : (char*)"fruits.jpg";
@@ -38,17 +51,10 @@ int main( int argc, char** argv )
     
     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);