From 534ac83b8d31c9c20e46ee052bd4e4b91275d935 Mon Sep 17 00:00:00 2001 From: Kirill Kornyakov Date: Sun, 29 May 2011 10:01:01 +0000 Subject: [PATCH] update help corresponding single format and update some samples through using CommandLineParser class --- samples/c/adaptiveskindetector.cpp | 6 ++-- samples/c/bgfg_codebook.cpp | 2 +- samples/c/contours.c | 2 +- samples/c/find_obj.cpp | 4 +-- samples/c/find_obj_calonder.cpp | 38 ++++++++++++++-------- samples/c/find_obj_ferns.cpp | 2 +- samples/c/latentsvmdetect.cpp | 3 +- samples/c/mser_sample.cpp | 4 +-- samples/c/one_way_sample.cpp | 10 ++++-- samples/c/tree_engine.cpp | 65 ++++++++++++++++++-------------------- 10 files changed, 73 insertions(+), 63 deletions(-) diff --git a/samples/c/adaptiveskindetector.cpp b/samples/c/adaptiveskindetector.cpp index 8afffba..fdb7f17 100644 --- a/samples/c/adaptiveskindetector.cpp +++ b/samples/c/adaptiveskindetector.cpp @@ -329,9 +329,9 @@ void help() "which can be found in contrib.cpp \n" "Usage: \n" "./adaptiveskindetector [--fileMask]= \n" - " if at least one parameter doesn't specified, it will try to use default webcam \n" + " [--firstFrame]= \n" + "if at least one parameter doesn't specified, it will try to use default webcam \n" "Expample: \n" " --fileMask = /home/user_home_directory/work/opencv/samples/c/temp_%%05d.jpg --firstFrame=0 --lastFrame=1000 \n"); } diff --git a/samples/c/bgfg_codebook.cpp b/samples/c/bgfg_codebook.cpp index 07c3ad6..8ee5b91 100644 --- a/samples/c/bgfg_codebook.cpp +++ b/samples/c/bgfg_codebook.cpp @@ -44,7 +44,7 @@ void help(void) "Originally from the book: Learning OpenCV by O'Reilly press\n" "\nUsage:\n" "./bgfg_codebook [--nframes]= \n" - " [--input]=\n" + " [--input]=\n" "***Keep the focus on the video windows, NOT the consol***\n\n" "INTERACTIVE PARAMETERS:\n" "\tESC,q,Q - quit the program\n" diff --git a/samples/c/contours.c b/samples/c/contours.c index 2999280..8cfd089 100644 --- a/samples/c/contours.c +++ b/samples/c/contours.c @@ -8,7 +8,7 @@ void help() "functions cvCreateMemStorage() and cvDrawContours().\n" "It also shows the use of a trackbar to control contour retrieval.\n" "\n" - "Call:\n" + "Usage :\n" "./contours\n"); } diff --git a/samples/c/find_obj.cpp b/samples/c/find_obj.cpp index 63f15df..c00b5ef 100644 --- a/samples/c/find_obj.cpp +++ b/samples/c/find_obj.cpp @@ -22,9 +22,9 @@ void help() printf( "This program demonstrated the use of the SURF Detector and Descriptor using\n" "either FLANN (fast approx nearst neighbor classification) or brute force matching\n" "on planar objects.\n" - "Call:\n" + "Usage :\n" "./find_obj [--object_filename]= \n" - "[--scene_filename]=]\n\n" + " [--scene_filename]=]\n\n" ); } diff --git a/samples/c/find_obj_calonder.cpp b/samples/c/find_obj_calonder.cpp index 1a5abe5..8f84b3d 100644 --- a/samples/c/find_obj_calonder.cpp +++ b/samples/c/find_obj_calonder.cpp @@ -11,14 +11,17 @@ using namespace cv; void help() { - cout << "This program shows the use of the Calonder point descriptor classifier" - "SURF is used to detect interest points, Calonder is used to describe/match these points\n" - "Format:" << endl << - " classifier_file(to write) test_image file_with_train_images_filenames(txt)" << - " or" << endl << - " classifier_file(to read) test_image" - "Using OpenCV version %s\n" << CV_VERSION << "\n" - << endl; + printf("\n This program shows the use of the Calonder point descriptor classifier \n" + "SURF is used to detect interest points, Calonder is used to describe/match these points \n" + "Usage: \n" + "./find_obj_calonder --classifier_file= \n" + " --test_image= \n" + " [--train_container]= \n" + "Example: \n" + " --classifier_file=test_classifier --test_image=lena.jpg --train_container=one_way_train_images.txt \n" + " the test_classifier is created here using --train_container and tested witn --test_image at the end \n" + " --classifier_file=test_classifier --test_image=lena.jpg \n" + " the test classifier is tested here using lena.jpg \n"); } /* * Generates random perspective transform of image @@ -144,18 +147,27 @@ void testCalonderClassifier( const string& classifierFilename, const string& img waitKey(); } -int main( int argc, char **argv ) +int main( int argc, const char **argv ) { - if( argc != 4 && argc != 3 ) + help(); + + CommandLineParser parser(argc, argv); + + string classifierFileName = parser.get("classifier_file"); + string testImageFileName = parser.get("test_image", "lena.jpg"); + string trainContainerFileName = parser.get("train_container"); + + if( classifierFileName.empty()) { + printf("\n Can't find classifier file, please select file for --classifier_file parameter \n"); help(); return -1; } - if( argc == 4 ) - trainCalonderClassifier( argv[1], argv[3] ); + if( !trainContainerFileName.empty()) + trainCalonderClassifier( classifierFileName.c_str(), trainContainerFileName.c_str() ); - testCalonderClassifier( argv[1], argv[2] ); + testCalonderClassifier( classifierFileName.c_str(), testImageFileName.c_str() ); return 0; } diff --git a/samples/c/find_obj_ferns.cpp b/samples/c/find_obj_ferns.cpp index 56c912a..8447903 100644 --- a/samples/c/find_obj_ferns.cpp +++ b/samples/c/find_obj_ferns.cpp @@ -16,7 +16,7 @@ void help() "descriptor classifier" "Usage:\n" "./find_obj_ferns [--object_filename]= \n" - "[--scene_filename]=]\n\n"); + " [--scene_filename]=] \n"); } int main(int argc, const char** argv) diff --git a/samples/c/latentsvmdetect.cpp b/samples/c/latentsvmdetect.cpp index f1e25b4..0097fe7 100644 --- a/samples/c/latentsvmdetect.cpp +++ b/samples/c/latentsvmdetect.cpp @@ -17,11 +17,10 @@ void help() { printf( "This program demonstrated the use of the latentSVM detector.\n" "It reads in a trained object model and then uses that to detect the object in an image\n" - "Call:\n" + "Usage: \n" "./latentsvmdetect [--image_filename]= \n" " [--model_filename] = \n" " [--threads_number] = \n" - " The defaults for image_filename and model_filename are cat.jpg and cat.xml respectively\n" " Press any key to quit.\n"); } diff --git a/samples/c/mser_sample.cpp b/samples/c/mser_sample.cpp index 5411c99..c465442 100644 --- a/samples/c/mser_sample.cpp +++ b/samples/c/mser_sample.cpp @@ -16,8 +16,8 @@ void help() { printf("\nThis program demonstrates the Maximal Extremal Region interest point detector.\n" "It finds the most stable (in size) dark and white regions as a threshold is increased.\n" - "\nCall:\n" - "./mser_sample [--image_filename] \n\n"); + "\n Usage: \n" + "./mser_sample [--image_filename] \n"); } static CvScalar colors[] = diff --git a/samples/c/one_way_sample.cpp b/samples/c/one_way_sample.cpp index 39e9b7d..285186b 100644 --- a/samples/c/one_way_sample.cpp +++ b/samples/c/one_way_sample.cpp @@ -18,9 +18,13 @@ void help() { printf("\nThis program demonstrates the one way interest point descriptor found in features2d.hpp\n" - "Correspondences are drawn\n"); - printf("Format: \n./one_way_sample \n"); - printf("For example: ./one_way_sample --path=../../../opencv/samples/c --first_image=scene_l.bmp --second_image=scene_r.bmp\n"); + "Correspondences are drawn\n" + "Usage: \n" + "./one_way_sample [--path]= \n" + " [--first_image]= \n" + " [--second_image]=\n" + "For example: \n" + " ./one_way_sample --path=../../../opencv/samples/c --first_image=scene_l.bmp --second_image=scene_r.bmp \n"); } using namespace cv; diff --git a/samples/c/tree_engine.cpp b/samples/c/tree_engine.cpp index 4f41884..0a851e4 100644 --- a/samples/c/tree_engine.cpp +++ b/samples/c/tree_engine.cpp @@ -1,21 +1,26 @@ +#include "opencv2/core/core.hpp" #include "opencv2/ml/ml.hpp" #include "opencv2/core/core_c.h" #include #include +using namespace std; +using namespace cv; + void help() { - printf( - "\nThis sample demonstrates how to use different decision trees and forests including boosting and random trees:\n" - "CvDTree dtree;\n" - "CvBoost boost;\n" - "CvRTrees rtrees;\n" - "CvERTrees ertrees;\n" - "CvGBTrees gbtrees;\n" - "Call:\n\t./tree_engine [-r ] [-c] \n" - "where -r specified the 0-based index of the response (0 by default)\n" - "-c specifies that the response is categorical (it's ordered by default) and\n" - " is the name of training data file in comma-separated value format\n\n"); + printf( + "\nThis sample demonstrates how to use different decision trees and forests including boosting and random trees:\n" + "CvDTree dtree;\n" + "CvBoost boost;\n" + "CvRTrees rtrees;\n" + "CvERTrees ertrees;\n" + "CvGBTrees gbtrees;\n" + "Usage: \n" + " ./tree_engine [--response_column]= \n" + "[--categorical_response]= \n" + "[--csv_filename]= \n" + ); } @@ -59,34 +64,24 @@ void print_result(float train_err, float test_err, const CvMat* _var_imp) printf("\n"); } -int main(int argc, char** argv) +int main(int argc, const char** argv) { - if(argc < 2) + help(); + + CommandLineParser parser(argc, argv); + + string filename = parser.get("csv_filename"); + int response_idx = parser.get("response_column", 0); + bool categorical_response = (bool)parser.get("categorical_response", 1); + + if(filename.empty()) { + printf("\n Please, select value for --csv_filename key \n"); help(); - return 0; - } - const char* filename = 0; - int response_idx = 0; - bool categorical_response = false; - - for(int i = 1; i < argc; i++) - { - if(strcmp(argv[i], "-r") == 0) - sscanf(argv[++i], "%d", &response_idx); - else if(strcmp(argv[i], "-c") == 0) - categorical_response = true; - else if(argv[i][0] != '-' ) - filename = argv[i]; - else - { - printf("Error. Invalid option %s\n", argv[i]); - help(); - return -1; - } + return -1; } - printf("\nReading in %s...\n\n",filename); + printf("\nReading in %s...\n\n",filename.c_str()); CvDTree dtree; CvBoost boost; CvRTrees rtrees; @@ -98,7 +93,7 @@ int main(int argc, char** argv) CvTrainTestSplit spl( 0.5f ); - if ( data.read_csv( filename ) == 0) + if ( data.read_csv( filename.c_str() ) == 0) { data.set_response_idx( response_idx ); if(categorical_response) -- 2.7.4