From e0f19ec48aa1f27f3cb607778cfc3d9b2138206f Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Wed, 27 Jul 2016 14:02:28 +0200 Subject: [PATCH] change parameter input to the CommandLineParser interface --- apps/annotation/opencv_annotation.cpp | 38 ++++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/annotation/opencv_annotation.cpp b/apps/annotation/opencv_annotation.cpp index d8ff61d..1bd22a2 100644 --- a/apps/annotation/opencv_annotation.cpp +++ b/apps/annotation/opencv_annotation.cpp @@ -224,28 +224,24 @@ vector get_annotations(Mat input_image) int main( int argc, const char** argv ) { - // If no arguments are given, then supply some information on how this tool works - if( argc == 1 ){ - cout << "Usage: " << argv[0] << endl; - cout << " -images [example - /data/testimages/]" << endl; - cout << " -annotations [example - /data/annotations.txt]" << endl; - cout << "TIP: Use absolute paths to avoid any problems with the software!" << endl; - return -1; - } - + // Use the cmdlineparser to process input arguments + CommandLineParser parser(argc, argv, + "{ help h usage ? | | show this message }" + "{ images i | | (required) path to image folder [example - /data/testimages/] }" + "{ annotations a | | (required) path to annotations txt file [example - /data/annotations.txt] }" + ); // Read in the input arguments - string image_folder; - string annotations_file; - for(int i = 1; i < argc; ++i ) - { - if( !strcmp( argv[i], "-images" ) ) - { - image_folder = argv[++i]; - } - else if( !strcmp( argv[i], "-annotations" ) ) - { - annotations_file = argv[++i]; - } + if (parser.has("help")){ + parser.printMessage(); + cerr << "TIP: Use absolute paths to avoid any problems with the software!" << endl; + return 0; + } + string image_folder(parser.get("images")); + string annotations_file(parser.get("annotations")); + if (image_folder.empty() || annotations_file.empty()){ + parser.printMessage(); + cerr << "TIP: Use absolute paths to avoid any problems with the software!" << endl; + return -1; } // Check if the folder actually exists -- 2.7.4