From 49fb4ecbc14decd958ef6ddf965f6a698254e29a Mon Sep 17 00:00:00 2001 From: itsyplen Date: Wed, 10 Aug 2011 10:41:38 +0000 Subject: [PATCH] Updated samples using new cmd parser --- samples/cpp/camshiftdemo.cpp | 59 +++++++++++++++++++----------------- samples/cpp/chamfer.cpp | 43 +++++++++++++++----------- 2 files changed, 57 insertions(+), 45 deletions(-) diff --git a/samples/cpp/camshiftdemo.cpp b/samples/cpp/camshiftdemo.cpp index fb518fdbd4..b726643f1b 100644 --- a/samples/cpp/camshiftdemo.cpp +++ b/samples/cpp/camshiftdemo.cpp @@ -8,24 +8,6 @@ using namespace cv; using namespace std; -void help() -{ - cout << "\nThis is a demo that shows mean-shift based tracking\n" - << "You select a color objects such as your face and it tracks it.\n" - << "This reads from video camera (0 by default, or the camera number the user enters\n" - << "Call:\n" - << "\n./camshiftdemo [camera number]" - << "\n" << endl; - - cout << "\n\nHot keys: \n" - "\tESC - quit the program\n" - "\tc - stop the tracking\n" - "\tb - switch to/from backprojection view\n" - "\th - show/hide object histogram\n" - "\tp - pause video\n" - "To initialize tracking, select the object with mouse\n" << endl; -} - Mat image; bool backprojMode = false; @@ -63,31 +45,52 @@ void onMouse( int event, int x, int y, int, void* ) } } +void help() +{ + printf("\nThis is a demo that shows mean-shift based tracking\n" + "You select a color objects such as your face and it tracks it.\n" + "This reads from video camera (0 by default, or the camera number the user enters\n" + "Usage: \n" + " ./camshiftdemo [camera number]\n"); + + printf("\n\nHot keys: \n" + "\tESC - quit the program\n" + "\tc - stop the tracking\n" + "\tb - switch to/from backprojection view\n" + "\th - show/hide object histogram\n" + "\tp - pause video\n" + "To initialize tracking, select the object with mouse\n"); +} +const char* keys = +{ + "{1| | 0 | camera number}" +}; -int main( int argc, char** argv ) +int main( int argc, const char** argv ) { + help(); + VideoCapture cap; Rect trackWindow; RotatedRect trackBox; int hsize = 16; float hranges[] = {0,180}; const float* phranges = hranges; - - if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) - cap.open(argc == 2 ? argv[1][0] - '0' : 0); - else if( argc == 2 ) - cap.open(argv[1]); + CommandLineParser parser(argc, argv, keys); + int camNum = parser.get("1"); + + cap.open(camNum); if( !cap.isOpened() ) { help(); - cout << "***Could not initialize capturing...***\n"; - return 0; + printf("***Could not initialize capturing...***\n"); + printf("Current parameter's value: \n"); + parser.printParams(); + return -1; } - help(); - namedWindow( "Histogram", 0 ); namedWindow( "CamShift Demo", 0 ); setMouseCallback( "CamShift Demo", onMouse, 0 ); diff --git a/samples/cpp/chamfer.cpp b/samples/cpp/chamfer.cpp index 9e4524a6bc..062873df7e 100644 --- a/samples/cpp/chamfer.cpp +++ b/samples/cpp/chamfer.cpp @@ -2,36 +2,45 @@ #include "opencv2/highgui/highgui.hpp" #include "opencv2/contrib/contrib.hpp" -#include - using namespace cv; using namespace std; void help() { - cout << - "\nThis program demonstrates Chamfer matching -- computing a distance between an \n" + + printf("\nThis program demonstrates Chamfer matching -- computing a distance between an \n" "edge template and a query edge image.\n" - "Usage:\n" + "Usage: \n" "./chamfer