From a1ee9d406efc7192893a7844d8aa88f795333098 Mon Sep 17 00:00:00 2001 From: itsyplen Date: Thu, 9 Jun 2011 08:37:39 +0000 Subject: [PATCH] Help and parsing command line were updated in next samples: camshiftdemo, calibration_artificial --- samples/cpp/calibration_artificial.cpp | 10 ++++---- samples/cpp/camshiftdemo.cpp | 44 ++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/samples/cpp/calibration_artificial.cpp b/samples/cpp/calibration_artificial.cpp index 6adb5bb..2f683ff 100644 --- a/samples/cpp/calibration_artificial.cpp +++ b/samples/cpp/calibration_artificial.cpp @@ -11,11 +11,11 @@ using namespace cv; using namespace std; void help() { - cout << "\nThis code generates an artificial camera and artificial chessboard images,\n" - << "and then calibrates. It is basically test code for calibration that shows\n" - << "how to package calibration points and then calibrate the camera.\n" - << "Call:\n" - << "./calibration_artificial\n" << endl; + printf( "\nThis code generates an artificial camera and artificial chessboard images,\n" + "and then calibrates. It is basically test code for calibration that shows\n" + "how to package calibration points and then calibrate the camera.\n" + "Usage:\n" + "./calibration_artificial\n\n"); } namespace cv { diff --git a/samples/cpp/camshiftdemo.cpp b/samples/cpp/camshiftdemo.cpp index 5fcd2c6..9e56fae 100644 --- a/samples/cpp/camshiftdemo.cpp +++ b/samples/cpp/camshiftdemo.cpp @@ -1,8 +1,10 @@ +#include "opencv2/core/core.hpp" #include "opencv2/video/tracking.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include +#include #include using namespace cv; @@ -10,19 +12,17 @@ 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" - "To initialize tracking, select the object with mouse\n" << endl; + 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 [--cameraIndex]=\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" + "To initialize tracking, select the object with mouse\n"); } Mat image; @@ -64,8 +64,13 @@ void onMouse( int event, int x, int y, int, void* ) -int main( int argc, char** argv ) +int main( int argc, const char** argv ) { + help(); + + CommandLineParser parser(argc, argv); + + unsigned int cameraInd = parser.get("cameraIndex", 0); VideoCapture cap; Rect trackWindow; RotatedRect trackBox; @@ -73,10 +78,11 @@ int main( int argc, char** argv ) 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]); +// 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]); + cap.open(cameraInd); if( !cap.isOpened() ) { @@ -85,8 +91,6 @@ int main( int argc, char** argv ) return 0; } - help(); - namedWindow( "Histogram", 1 ); namedWindow( "CamShift Demo", 1 ); setMouseCallback( "CamShift Demo", onMouse, 0 ); -- 2.7.4