From: AoD314 Date: Fri, 7 Sep 2012 09:24:48 +0000 (+0400) Subject: add new version of CommandLineParser. add empty docs X-Git-Tag: accepted/2.0/20130307.220821~364^2~210^2~69 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54a202b3d522f19a05993998ab40a40733a0d3b8;p=profile%2Fivi%2Fopencv.git add new version of CommandLineParser. add empty docs --- diff --git a/modules/core/doc/command_line_parser.rst b/modules/core/doc/command_line_parser.rst new file mode 100644 index 0000000..5f0e512 --- /dev/null +++ b/modules/core/doc/command_line_parser.rst @@ -0,0 +1,101 @@ +Command Line Parser +=================== + +.. highlight:: cpp + +CommandLineParser +-------- +.. ocv:class:: CommandLineParser + +The CommandLineParser class is designed for command line arguments parsing + + + .. ocv:function:: CommandLineParser::CommandLineParser(int argc, const char * const argv[], const std::string keys) + + :param argc: + :param argv: + :param keys: + + .. ocv:function:: T CommandLineParser::get(const std::string& name, bool space_delete = true) + + :param name: + :param space_delete: + + .. ocv:function:: T CommandLineParser::get(int index, bool space_delete = true) + + :param index: + :param space_delete: + + .. ocv:function:: bool CommandLineParser::has(const std::string& name) + + :param name: + + .. ocv:function:: bool CommandLineParser::check() + + + .. ocv:function:: void CommandLineParser::about(std::string message) + + :param message: + + .. ocv:function:: void CommandLineParser::printMessage() + + .. ocv:function:: void CommandLineParser::printErrors() + + .. ocv:function:: std::string CommandLineParser::getPathToApplication() + + +The sample below demonstrates how to use CommandLineParser: + +:: + + CommandLineParser parser(argc, argv, keys); + parser.about("Application name v1.0.0"); + + if (parser.has("help")) + { + parser.printMessage(); + return 0; + } + + int N = parser.get("N"); + double fps = parser.getparser("fps"); + std::string path = parser.get("path"); + + use_time_stamp = parserer.has("timestamp"); + + std::string img1 = parser.get(1); + std::string img2 = parser.get(2); + + int repeat = parser.get(3); + + if (!parser.check()) + { + parser.printErrors(); + return 0; + } + +Syntax: + +:: + + const std::string keys = + "{help h usage ? | | print this message }" + "{@image1 | | image1 for compare }" + "{@image2 | | image2 for compare }" + "{@repeat |1 | number }" + "{path |. | path to file }" + "{fps | -1.0 | fps for output video }" + "{N count |100 | count of objects }" + "{ts timestamp | | use time stamp }" + ; + +Use: + +:: + + # ./app -N=200 1.png 2.jpg 19 -ts + + # ./app -fps=aaa + ERRORS: + Exception: can not convert: [aaa] to [double] + diff --git a/modules/core/doc/core.rst b/modules/core/doc/core.rst index 7eb4e3e..90caeeb 100644 --- a/modules/core/doc/core.rst +++ b/modules/core/doc/core.rst @@ -6,6 +6,7 @@ core. The Core Functionality :maxdepth: 2 basic_structures + command_line_parser old_basic_structures dynamic_structures operations_on_arrays diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index f03f21b..2496c80 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -4505,113 +4505,143 @@ template<> struct ParamType enum { type = Param::ALGORITHM }; }; +// The CommandLineParser class is designed for command line arguments parsing -/*! -"\nThe CommandLineParser class is designed for command line arguments parsing\n" - "Keys map: \n" - "Before you start to work with CommandLineParser you have to create a map for keys.\n" - " It will look like this\n" - " const char* keys =\n" - " {\n" - " { s| string| 123asd |string parameter}\n" - " { d| digit | 100 |digit parameter }\n" - " { c|noCamera|false |without camera }\n" - " { 1| |some text|help }\n" - " { 2| |333 |another help }\n" - " };\n" - "Usage syntax: \n" - " \"{\" - start of parameter string.\n" - " \"}\" - end of parameter string\n" - " \"|\" - separator between short name, full name, default value and help\n" - "Supported syntax: \n" - " --key1=arg1 \n" - " -key2=arg2 \n" - "Usage: \n" - " Imagine that the input parameters are next:\n" - " -s=string_value --digit=250 --noCamera lena.jpg 10000\n" - " CommandLineParser parser(argc, argv, keys) - create a parser object\n" - " parser.get(\"s\" or \"string\") will return you first parameter value\n" - " parser.get(\"s\", false or \"string\", false) will return you first parameter value\n" - " without spaces in end and begin\n" - " parser.get(\"d\" or \"digit\") will return you second parameter value.\n" - " It also works with 'unsigned int', 'double', and 'float' types>\n" - " parser.get(\"c\" or \"noCamera\") will return you true .\n" - " If you enter this key in commandline>\n" - " It return you false otherwise.\n" - " parser.get(\"1\") will return you the first argument without parameter (lena.jpg) \n" - " parser.get(\"2\") will return you the second argument without parameter (10000)\n" - " It also works with 'unsigned int', 'double', and 'float' types \n" -*/ -class CV_EXPORTS CommandLineParser +class CV_EXPORTS CommandLineParserParams { public: + std::string help_message; + std::string def_value; + std::vector keys; + int number; +}; - //! the default constructor - CommandLineParser(int argc, const char* const argv[], const char* key_map); +template +std::string get_type_name() { return "UNKNOW"; } + +bool cmp_params(const CommandLineParserParams & p1, const CommandLineParserParams & p2); + +template +T from_str(const std::string & str) +{ + T value; + std::stringstream ss(str); + ss >> value; - //! get parameter, you can choose: delete spaces in end and begin or not - template - _Tp get(const std::string& name, bool space_delete=true) + if (ss.fail()) { - if (!has(name)) - { - return _Tp(); - } - std::string str = getString(name); - return analyzeValue<_Tp>(str, space_delete); + std::string err_msg = + std::string("can not convert: [") + + str + + std::string("] to [") + + get_type_name() + + std::string("]"); + + CV_Error(CV_StsBadArg, err_msg); } - //! print short name, full name, current value and help for all params - void printParams(); + return value; +} - protected: - std::map > data; - std::string getString(const std::string& name); +template<> std::string from_str(const std::string & str); + +template +std::string to_str(T value) +{ + std::ostringstream os; + os << value; + return os.str(); +} - bool has(const std::string& keys); +class CV_EXPORTS CommandLineParser +{ + public: + CommandLineParser(int argc, const char * const argv[], const std::string keys); - template - _Tp analyzeValue(const std::string& str, bool space_delete=false); + std::string getPathToApplication(); - template - static _Tp getData(const std::string& str) - { - _Tp res; - std::stringstream s1(str); - s1 >> res; - return res; - } + template + T get(const std::string& name, bool space_delete = true) + { + try + { + for (size_t i = 0; i < data.size(); i++) + { + for (size_t j = 0; j < data[i].keys.size(); j++) + { + if (name.compare(data[i].keys[j]) == 0) + { + std::string v = data[i].def_value; + if (space_delete == true) v = cat_string(v); + return from_str(v); + } + } + } + error = true; + error_message += "Unknown parametes " + name + "\n"; + } + catch (std::exception& e) + { + error = true; + error_message += "Exception: " + std::string(e.what()) + "\n"; + } + return T(); + } - template - _Tp fromStringNumber(const std::string& str);//the default conversion function for numbers + template + T get(int index, bool space_delete = true) + { + try + { + for (size_t i = 0; i < data.size(); i++) + { + if (data[i].number == index - 1) + { + std::string v = data[i].def_value; + if (space_delete == true) v = cat_string(v); + return from_str(v); + } + } + error = true; + error_message += "Unknown parametes #" + to_str(index) + "\n"; + } + catch(std::exception & e) + { + error = true; + error_message += "Exception: " + std::string(e.what()) + "\n"; + } + return T(); + } - }; + bool has(const std::string& name); -template<> CV_EXPORTS -bool CommandLineParser::get(const std::string& name, bool space_delete); + bool check(); -template<> CV_EXPORTS -std::string CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + void about(std::string message); -template<> CV_EXPORTS -int CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + void printMessage(); + void printErrors(); + + protected: + bool error; + std::string error_message; + std::string about_message; -template<> CV_EXPORTS -unsigned int CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + std::string path_to_app; + std::string app_name; -template<> CV_EXPORTS -uint64 CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + std::vector data; -template<> CV_EXPORTS -float CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + std::vector split_range_string(std::string str, char fs, char ss); + std::vector split_string(std::string str, char symbol = ' ', bool create_empty_item = false); + std::string cat_string(std::string str); -template<> CV_EXPORTS -double CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + void apply_params(std::string key, std::string value); + void apply_params(int i, std::string value); + + void sort_params(); + +}; /////////////////////////////// Parallel Primitives ////////////////////////////////// diff --git a/modules/core/src/cmdparser.cpp b/modules/core/src/cmdparser.cpp deleted file mode 100644 index d7be054..0000000 --- a/modules/core/src/cmdparser.cpp +++ /dev/null @@ -1,384 +0,0 @@ -#include "precomp.hpp" - -#include -#include - -using namespace std; -using namespace cv; - -namespace { -#if 0 -static void helpParser() -{ - printf("\nThe CommandLineParser class is designed for command line arguments parsing\n" - "Keys map: \n" - "Before you start to work with CommandLineParser you have to create a map for keys.\n" - " It will look like this\n" - " const char* keys =\n" - " {\n" - " { s| string| 123asd |string parameter}\n" - " { d| digit | 100 |digit parameter }\n" - " { c|noCamera|false |without camera }\n" - " { 1| |some text|help }\n" - " { 2| |333 |another help }\n" - " };\n" - "Usage syntax: \n" - " \"{\" - start of parameter string.\n" - " \"}\" - end of parameter string\n" - " \"|\" - separator between short name, full name, default value and help\n" - "Supported syntax: \n" - " --key1=arg1 \n" - " -key2=arg2 \n" - "Usage: \n" - " Imagine that the input parameters are next:\n" - " -s=string_value --digit=250 --noCamera lena.jpg 10000\n" - " CommandLineParser parser(argc, argv, keys) - create a parser object\n" - " parser.get(\"s\" or \"string\") will return you first parameter value\n" - " parser.get(\"s\", false or \"string\", false) will return you first parameter value\n" - " without spaces in end and begin\n" - " parser.get(\"d\" or \"digit\") will return you second parameter value.\n" - " It also works with 'unsigned int', 'double', and 'float' types>\n" - " parser.get(\"c\" or \"noCamera\") will return you true .\n" - " If you enter this key in commandline>\n" - " It return you false otherwise.\n" - " parser.get(\"1\") will return you the first argument without parameter (lena.jpg) \n" - " parser.get(\"2\") will return you the second argument without parameter (10000)\n" - " It also works with 'unsigned int', 'double', and 'float' types \n" - ); -} -#endif - -vector split_string(const string& str, const string& delimiters) -{ - vector res; - - string split_str = str; - size_t pos_delim = split_str.find(delimiters); - - while ( pos_delim != string::npos) - { - if (pos_delim == 0) - { - res.push_back(""); - split_str.erase(0, 1); - } - else - { - res.push_back(split_str.substr(0, pos_delim)); - split_str.erase(0, pos_delim + 1); - } - - pos_delim = split_str.find(delimiters); - } - - res.push_back(split_str); - - return res; -} - -string del_space(string name) -{ - while ((name.find_first_of(' ') == 0) && (name.length() > 0)) - name.erase(0, 1); - - while ((name.find_last_of(' ') == (name.length() - 1)) && (name.length() > 0)) - name.erase(name.end() - 1, name.end()); - - return name; -} - -}//namespace - -CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys) -{ - std::string keys_buffer; - std::string values_buffer; - std::string buffer; - std::string curName; - std::vector keysVector; - std::vector paramVector; - std::map >::iterator it; - size_t flagPosition; - int currentIndex = 1; - //bool isFound = false; - bool withNoKey = false; - bool hasValueThroughEq = false; - - keys_buffer = keys; - while (!keys_buffer.empty()) - { - - flagPosition = keys_buffer.find_first_of('}'); - flagPosition++; - buffer = keys_buffer.substr(0, flagPosition); - keys_buffer.erase(0, flagPosition); - - flagPosition = buffer.find('{'); - if (flagPosition != buffer.npos) - buffer.erase(flagPosition, (flagPosition + 1)); - - flagPosition = buffer.find('}'); - if (flagPosition != buffer.npos) - buffer.erase(flagPosition); - - paramVector = split_string(buffer, "|"); - while (paramVector.size() < 4) paramVector.push_back(""); - - buffer = paramVector[0]; - buffer += '|' + paramVector[1]; - - //if (buffer == "") CV_ERROR(CV_StsBadArg, "In CommandLineParser need set short and full name"); - - paramVector.erase(paramVector.begin(), paramVector.begin() + 2); - data[buffer] = paramVector; - } - - buffer.clear(); - keys_buffer.clear(); - paramVector.clear(); - for (int i = 1; i < argc; i++) - { - if (!argv[i]) - break; - curName = argv[i]; - if (curName.find('-') == 0 && ((curName[1] < '0') || (curName[1] > '9'))) - { - while (curName.find('-') == 0) - curName.erase(curName.begin(), (curName.begin() + 1)); - } - else - withNoKey = true; - if (curName.find('=') != curName.npos) - { - hasValueThroughEq = true; - buffer = curName; - curName.erase(curName.find('=')); - buffer.erase(0, (buffer.find('=') + 1)); - } - - values_buffer = del_space(values_buffer); - - for(it = data.begin(); it != data.end(); it++) - { - keys_buffer = it->first; - keysVector = split_string(keys_buffer, "|"); - - for (size_t j = 0; j < keysVector.size(); j++) keysVector[j] = del_space(keysVector[j]); - - values_buffer = it->second[0]; - if (((curName == keysVector[0]) || (curName == keysVector[1])) && hasValueThroughEq) - { - it->second[0] = buffer; - //isFound = true; - break; - } - - if (!hasValueThroughEq && ((curName == keysVector[0]) || (curName == keysVector[1])) - && ( - values_buffer.find("false") != values_buffer.npos || - values_buffer == "" - )) - { - it->second[0] = "true"; - //isFound = true; - break; - } - - if (!hasValueThroughEq && (values_buffer.find("false") == values_buffer.npos) && - ((curName == keysVector[0]) || (curName == keysVector[1]))) - { - it->second[0] = argv[++i]; - //isFound = true; - break; - } - - - if (withNoKey) - { - std::string noKeyStr = it->first; - if(atoi(noKeyStr.c_str()) == currentIndex) - { - it->second[0] = curName; - currentIndex++; - //isFound = true; - break; - } - } - } - - withNoKey = false; - hasValueThroughEq = false; - //isFound = false; - } -} - -bool CommandLineParser::has(const std::string& keys) -{ - std::map >::iterator it; - std::vector keysVector; - - for(it = data.begin(); it != data.end(); it++) - { - keysVector = split_string(it->first, "|"); - for (size_t i = 0; i < keysVector.size(); i++) keysVector[i] = del_space(keysVector[i]); - - if (keysVector.size() == 1) keysVector.push_back(""); - - if ((del_space(keys).compare(keysVector[0]) == 0) || - (del_space(keys).compare(keysVector[1]) == 0)) - return true; - } - - return false; -} - -std::string CommandLineParser::getString(const std::string& keys) -{ - std::map >::iterator it; - std::vector valueVector; - - for(it = data.begin(); it != data.end(); it++) - { - valueVector = split_string(it->first, "|"); - for (size_t i = 0; i < valueVector.size(); i++) valueVector[i] = del_space(valueVector[i]); - - if (valueVector.size() == 1) valueVector.push_back(""); - - if ((del_space(keys).compare(valueVector[0]) == 0) || - (del_space(keys).compare(valueVector[1]) == 0)) - return it->second[0]; - } - return string(); -} - -template - _Tp CommandLineParser::fromStringNumber(const std::string& str)//the default conversion function for numbers -{ - return getData<_Tp>(str); -} - - void CommandLineParser::printParams() - { - int col_p = 30; - int col_d = 50; - - std::map >::iterator it; - std::vector keysVector; - std::string buf; - for(it = data.begin(); it != data.end(); it++) - { - keysVector = split_string(it->first, "|"); - for (size_t i = 0; i < keysVector.size(); i++) keysVector[i] = del_space(keysVector[i]); - - cout << " "; - buf = ""; - if (keysVector[0] != "") - { - buf = "-" + keysVector[0]; - if (keysVector[1] != "") buf += ", --" + keysVector[1]; - } - else if (keysVector[1] != "") buf += "--" + keysVector[1]; - if (del_space(it->second[0]) != "") buf += "=[" + del_space(it->second[0]) + "]"; - - cout << setw(col_p-2) << left << buf; - - if ((int)buf.length() > col_p-2) - { - cout << endl << " "; - cout << setw(col_p-2) << left << " "; - } - - buf = ""; - if (del_space(it->second[1]) != "") buf += del_space(it->second[1]); - - for(;;) - { - bool tr = ((int)buf.length() > col_d-2) ? true: false; - std::string::size_type pos = 0; - - if (tr) - { - pos = buf.find_first_of(' '); - for(;;) - { - if (buf.find_first_of(' ', pos + 1 ) < (std::string::size_type)(col_d-2) && - buf.find_first_of(' ', pos + 1 ) != std::string::npos) - pos = buf.find_first_of(' ', pos + 1); - else - break; - } - pos++; - cout << setw(col_d-2) << left << buf.substr(0, pos) << endl; - } - else - { - cout << setw(col_d-2) << left << buf<< endl; - break; - } - - buf.erase(0, pos); - cout << " "; - cout << setw(col_p-2) << left << " "; - } - } - } - -template<> -bool CommandLineParser::get(const std::string& name, bool space_delete) -{ - std::string str_buf = getString(name); - - if (space_delete && str_buf != "") - { - str_buf = del_space(str_buf); - } - - if (str_buf == "true") - return true; - - return false; -} -template<> -std::string CommandLineParser::analyzeValue(const std::string& str, bool space_delete) -{ - if (space_delete) - { - return del_space(str); - } - return str; -} - -template<> -int CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) -{ - return fromStringNumber(str); -} - -template<> -unsigned int CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) -{ - return fromStringNumber(str); -} - -template<> -uint64 CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) -{ - return fromStringNumber(str); -} - -template<> -float CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) -{ - return fromStringNumber(str); -} - -template<> -double CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) -{ - return fromStringNumber(str); -} diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp new file mode 100644 index 0000000..dc137e7 --- /dev/null +++ b/modules/core/src/command_line_parser.cpp @@ -0,0 +1,406 @@ + +#include "precomp.hpp" + +#include + +namespace cv +{ + bool cmp_params(const CommandLineParserParams & p1, const CommandLineParserParams & p2) + { + if (p1.number > p2.number) + return false; + + if (p1.number == -1 && p2.number == -1) + { + if (p1.keys[0].compare(p2.keys[0]) > 0) + { + return false; + } + } + + return true; + } + + CommandLineParser::CommandLineParser(int argc, const char * const argv[], const std::string keys) + { + // path to application + size_t pos_s = std::string(argv[0]).find_last_of("/\\"); + if (pos_s == std::string::npos) + { + path_to_app = ""; + app_name = std::string(argv[0]); + } + else + { + path_to_app = std::string(argv[0]).substr(0, pos_s); + app_name = std::string(argv[0]).substr(pos_s + 1, std::string(argv[0]).length() - pos_s); + } + + error = false; + error_message = ""; + + // parse keys + std::vector k = split_range_string(keys, '{', '}'); + + int jj = 0; + for (size_t i = 0; i < k.size(); i++) + { + std::vector l = split_string(k[i], '|', true); + CommandLineParserParams p; + p.keys = split_string(l[0]); + p.def_value = l[1]; + p.help_message = cat_string(l[2]); + p.number = -1; + if (p.keys[0][0] == '@') + { + p.number = jj; + jj++; + } + + data.push_back(p); + } + + // parse argv + jj = 0; + for (int i = 1; i < argc; i++) + { + std::string s = std::string(argv[i]); + + if (s.find('=') != std::string::npos && s.find('=') < s.length()) + { + std::vector k_v = split_string(s, '=', true); + for (int h = 0; h < 2; h++) + { + if (k_v[0][0] == '-') + k_v[0] = k_v[0].substr(1, k_v[0].length() -1); + } + apply_params(k_v[0], k_v[1]); + } + else if (s.length() > 1 && s[0] == '-') + { + for (int h = 0; h < 2; h++) + { + if (s[0] == '-') + s = s.substr(1, s.length() - 1); + } + apply_params(s, "true"); + } + else if (s[0] != '-') + { + apply_params(jj, s); + jj++; + } + } + + sort_params(); + } + + void CommandLineParser::about(std::string message) + { + about_message = message; + } + + void CommandLineParser::apply_params(std::string key, std::string value) + { + for (size_t i = 0; i < data.size(); i++) + { + for (size_t k = 0; k < data[i].keys.size(); k++) + { + if (key.compare(data[i].keys[k]) == 0) + { + data[i].def_value = value; + break; + } + } + } + } + + void CommandLineParser::apply_params(int i, std::string value) + { + for (size_t j = 0; j < data.size(); j++) + { + if (data[j].number == i) + { + data[j].def_value = value; + break; + } + } + } + + void CommandLineParser::sort_params() + { + for (size_t i = 0; i < data.size(); i++) + { + sort(data[i].keys.begin(), data[i].keys.end()); + } + + sort (data.begin(), data.end(), cmp_params); + } + + std::string CommandLineParser::cat_string(std::string str) + { + while (!str.empty() && str[0] == ' ') + { + str = str.substr(1, str.length() - 1); + } + + while (!str.empty() && str[str.length() - 1] == ' ') + { + str = str.substr(0, str.length() - 1); + } + + return str; + } + + std::string CommandLineParser::getPathToApplication() + { + return path_to_app; + } + + bool CommandLineParser::has(const std::string& name) + { + for (size_t i = 0; i < data.size(); i++) + { + for (size_t j = 0; j < data[i].keys.size(); j++) + { + if (name.compare(data[i].keys[j]) == 0 && std::string("true").compare(data[i].def_value) == 0) + { + return true; + } + } + } + return false; + } + + bool CommandLineParser::check() + { + return error == false; + } + + void CommandLineParser::printErrors() + { + if (error) + { + std::cout << std::endl << "ERRORS:" << std::endl << error_message << std::endl; + } + } + + void CommandLineParser::printMessage() + { + if (about_message != "") + std::cout << about_message << std::endl; + + std::cout << "Usage: " << app_name << " [params] "; + + for (size_t i = 0; i < data.size(); i++) + { + if (data[i].number > -1) + { + std::string name = data[i].keys[0].substr(1, data[i].keys[0].length() - 1); + std::cout << name << " "; + } + } + + std::cout << std::endl << std::endl; + + for (size_t i = 0; i < data.size(); i++) + { + if (data[i].number == -1) + { + std::cout << "\t"; + for (size_t j = 0; j < data[i].keys.size(); j++) + { + std::string k = data[i].keys[j]; + if (k.length() > 1) + { + std::cout << "--"; + } + else + { + std::cout << "-"; + } + std::cout << k; + + if (j != data[i].keys.size() - 1) + { + std::cout << ", "; + } + } + std::string dv = cat_string(data[i].def_value); + if (dv.compare("") != 0) + { + std::cout << " (value:" << dv << ")"; + } + std::cout << std::endl << "\t\t" << data[i].help_message << std::endl; + } + } + std::cout << std::endl; + + for (size_t i = 0; i < data.size(); i++) + { + if (data[i].number != -1) + { + std::cout << "\t"; + std::string k = data[i].keys[0]; + k = k.substr(1, k.length() - 1); + + std::cout << k; + + std::string dv = cat_string(data[i].def_value); + if (dv.compare("") != 0) + { + std::cout << " (value:" << dv << ")"; + } + std::cout << std::endl << "\t\t" << data[i].help_message << std::endl; + } + } + } + + std::vector CommandLineParser::split_range_string(std::string str, char fs, char ss) + { + std::vector vec; + std::string word = ""; + bool begin = false; + + while (!str.empty()) + { + if (str[0] == fs) + { + if (begin == true) + { + CV_Error(CV_StsParseError, + std::string("error in split_range_string(") + + str + + std::string(", ") + + std::string(1, fs) + + std::string(", ") + + std::string(1, ss) + + std::string(")") + ); + } + begin = true; + word = ""; + str = str.substr(1, str.length() - 1); + } + + if (str[0] == ss) + { + if (begin == false) + { + CV_Error(CV_StsParseError, + std::string("error in split_range_string(") + + str + + std::string(", ") + + std::string(1, fs) + + std::string(", ") + + std::string(1, ss) + + std::string(")") + ); + } + begin = false; + vec.push_back(word); + } + + if (begin == true) + { + word += str[0]; + } + str = str.substr(1, str.length() - 1); + } + + if (begin == true) + { + CV_Error(CV_StsParseError, + std::string("error in split_range_string(") + + str + + std::string(", ") + + std::string(1, fs) + + std::string(", ") + + std::string(1, ss) + + std::string(")") + ); + } + + return vec; + } + + std::vector CommandLineParser::split_string(std::string str, char symbol, bool create_empty_item) + { + std::vector vec; + std::string word = ""; + + while (!str.empty()) + { + if (str[0] == symbol) + { + if (!word.empty() || create_empty_item) + { + vec.push_back(word); + word = ""; + } + } + else + { + word += str[0]; + } + str = str.substr(1, str.length() - 1); + } + + if (word != "" || create_empty_item) + { + vec.push_back(word); + } + + return vec; + } + + #undef clp_get + #define clp_get(T) template<> T CommandLineParser::get(const std::string& name, bool space_delete); + + clp_get(int) + clp_get(unsigned int) + clp_get(long) + clp_get(unsigned long) + clp_get(long long) + clp_get(unsigned long long) + clp_get(size_t) + clp_get(float) + clp_get(double) + clp_get(uint64) + clp_get(int64) + clp_get(std::string) + + #undef clp_from_str + #define clp_from_str(T) template<> T from_str(const std::string & str); + + clp_from_str(int) + clp_from_str(unsigned int) + clp_from_str(long) + clp_from_str(unsigned long) + clp_from_str(long long) + clp_from_str(unsigned long long) + clp_from_str(size_t) + clp_from_str(uint64) + clp_from_str(int64) + clp_from_str(float) + clp_from_str(double) + + template<> + std::string from_str(const std::string & str) + { + return str; + } + + #undef clp_type_name + #define clp_type_name(type, name) template<> std::string get_type_name() { return std::string(name);} + + clp_type_name(int, "int") + clp_type_name(unsigned int, "unsigned int") + clp_type_name(long, "long") + clp_type_name(long long, "long long") + clp_type_name(unsigned long long, "unsigned long long") + clp_type_name(size_t, "size_t") + clp_type_name(float, "float") + clp_type_name(double, "double") + +} diff --git a/modules/gpu/perf/main.cpp b/modules/gpu/perf/main.cpp index aadeee9..8d34041 100644 --- a/modules/gpu/perf/main.cpp +++ b/modules/gpu/perf/main.cpp @@ -73,20 +73,32 @@ void printCudaInfo() int main(int argc, char** argv) { - CommandLineParser cmd(argc, (const char**) argv, - "{ print_info_only | print_info_only | false | Print information about system and exit }" - "{ device | device | 0 | Device on which tests will be executed }" - "{ cpu | cpu | false | Run tests on cpu }" - ); + const std::string keys = + "{ h help ? | | Print help}" + "{ i info | | Print information about system and exit }" + "{ device | 0 | Device on which tests will be executed }" + "{ cpu | | Run tests on cpu }" + ; + + CommandLineParser cmd(argc, (const char**) argv, keys); + + if (cmd.has("help")) + { + cmd.printMessage(); + return 0; + } printOsInfo(); printCudaInfo(); - if (cmd.get("print_info_only")) + + if (cmd.has("info")) + { return 0; + } int device = cmd.get("device"); - bool cpu = cmd.get("cpu"); + bool cpu = cmd.has("cpu"); #ifndef HAVE_CUDA cpu = true; #endif diff --git a/modules/gpu/test/main.cpp b/modules/gpu/test/main.cpp index 8f216c9..2e1edf0 100644 --- a/modules/gpu/test/main.cpp +++ b/modules/gpu/test/main.cpp @@ -118,17 +118,28 @@ int main(int argc, char** argv) { try { - CommandLineParser cmd(argc, (const char**)argv, - "{ print_info_only | print_info_only | false | Print information about system and exit }" - "{ device | device | -1 | Device on which tests will be executed (-1 means all devices) }" - "{ nvtest_output_level | nvtest_output_level | compact | NVidia test verbosity level }" - ); + const std::string keys = + "{ h help ? | | Print help}" + "{ i info | | Print information about system and exit }" + "{ device | -1 | Device on which tests will be executed (-1 means all devices) }" + "{ nvtest_output_level | compact | NVidia test verbosity level (none, compact, full) }" + ; + + CommandLineParser cmd(argc, (const char**)argv, keys); + + if (cmd.has("help")) + { + cmd.printMessage(); + return 0; + } printOsInfo(); printCudaInfo(); - if (cmd.get("print_info_only")) + if (cmd.has("info")) + { return 0; + } int device = cmd.get("device"); if (device < 0) diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index cd389f1..0bb5d9c 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -10,24 +10,23 @@ int64 TestBase::timeLimitDefault = 0; unsigned int TestBase::iterationsLimitDefault = (unsigned int)(-1); int64 TestBase::_timeadjustment = 0; -const char *command_line_keys = -{ - "{ |perf_max_outliers |8 |percent of allowed outliers}" - "{ |perf_min_samples |10 |minimal required numer of samples}" - "{ |perf_force_samples |100 |force set maximum number of samples for all tests}" - "{ |perf_seed |809564 |seed for random numbers generator}" - "{ |perf_tbb_nthreads |-1 |if TBB is enabled, the number of TBB threads}" - "{ |perf_write_sanity |false |allow to create new records for sanity checks}" +const std::string command_line_keys = + "{ perf_max_outliers |8 |percent of allowed outliers}" + "{ perf_min_samples |10 |minimal required numer of samples}" + "{ perf_force_samples |100 |force set maximum number of samples for all tests}" + "{ perf_seed |809564 |seed for random numbers generator}" + "{ perf_tbb_nthreads |-1 |if TBB is enabled, the number of TBB threads}" + "{ perf_write_sanity | |allow to create new records for sanity checks}" #ifdef ANDROID - "{ |perf_time_limit |6.0 |default time limit for a single test (in seconds)}" - "{ |perf_affinity_mask |0 |set affinity mask for the main thread}" - "{ |perf_log_power_checkpoints |false |additional xml logging for power measurement}" + "{ perf_time_limit |6.0 |default time limit for a single test (in seconds)}" + "{ perf_affinity_mask |0 |set affinity mask for the main thread}" + "{ perf_log_power_checkpoints | |additional xml logging for power measurement}" #else - "{ |perf_time_limit |3.0 |default time limit for a single test (in seconds)}" + "{ perf_time_limit |3.0 |default time limit for a single test (in seconds)}" #endif - "{ |perf_max_deviation |1.0 |}" - "{h |help |false |}" -}; + "{ perf_max_deviation |1.0 |}" + "{ help h | |print help info}" +; static double param_max_outliers; static double param_max_deviation; @@ -526,23 +525,28 @@ performance_metrics::performance_metrics() void TestBase::Init(int argc, const char* const argv[]) { cv::CommandLineParser args(argc, argv, command_line_keys); - param_max_outliers = std::min(100., std::max(0., args.get("perf_max_outliers"))); - param_min_samples = std::max(1u, args.get("perf_min_samples")); + if (args.has("help")) + { + args.printMessage(); + return; + } + + param_max_outliers = std::min(100., std::max(0., args.get("perf_max_outliers"))); + param_min_samples = std::max(1u, args.get("perf_min_samples")); param_max_deviation = std::max(0., args.get("perf_max_deviation")); - param_seed = args.get("perf_seed"); - param_time_limit = std::max(0., args.get("perf_time_limit")); + param_seed = args.get("perf_seed"); + param_time_limit = std::max(0., args.get("perf_time_limit")); param_force_samples = args.get("perf_force_samples"); - param_write_sanity = args.get("perf_write_sanity"); + param_write_sanity = args.has("perf_write_sanity"); param_tbb_nthreads = args.get("perf_tbb_nthreads"); #ifdef ANDROID - param_affinity_mask = args.get("perf_affinity_mask"); - log_power_checkpoints = args.get("perf_log_power_checkpoints"); + param_affinity_mask = args.get("perf_affinity_mask"); + log_power_checkpoints = args.has("perf_log_power_checkpoints"); #endif - if (args.get("help")) + if (!args.check()) { - args.printParams(); - printf("\n\n"); + args.printErrors(); return; } diff --git a/samples/c/bgfg_codebook.cpp b/samples/c/bgfg_codebook.cpp index 2b15728..3054e99 100644 --- a/samples/c/bgfg_codebook.cpp +++ b/samples/c/bgfg_codebook.cpp @@ -72,9 +72,9 @@ static void help() // const char *keys = { - "{nf|nframes |300 |frames number}" - "{c |camera |false |use the camera or not}" - "{mf|movie_file|tree.avi |used movie video file}" + "{nf nframes |300 |frames number}" + "{c camera |false |use the camera or not}" + "{mf movie_file|tree.avi |used movie video file}" }; int main(int argc, const char** argv) { @@ -82,7 +82,7 @@ int main(int argc, const char** argv) CommandLineParser parser(argc, argv, keys); int nframesToLearnBG = parser.get("nf"); - bool useCamera = parser.get("c"); + bool useCamera = parser.has("c"); string filename = parser.get("mf"); IplImage* rawImage = 0, *yuvImage = 0; //yuvImage is for codebook method IplImage *ImaskCodeBook = 0,*ImaskCodeBookCC = 0; diff --git a/samples/cpp/bgfg_segm.cpp b/samples/cpp/bgfg_segm.cpp index ffb2382..72566ea 100644 --- a/samples/cpp/bgfg_segm.cpp +++ b/samples/cpp/bgfg_segm.cpp @@ -18,8 +18,8 @@ static void help() const char* keys = { - "{c |camera |true | use camera or not}" - "{fn|file_name|tree.avi | movie file }" + "{c camera | | use camera or not}" + "{fn file_name|tree.avi | movie file }" }; //this is a sample for foreground detection functions @@ -28,7 +28,7 @@ int main(int argc, const char** argv) help(); CommandLineParser parser(argc, argv, keys); - bool useCamera = parser.get("camera"); + bool useCamera = parser.has("camera"); string file = parser.get("file_name"); VideoCapture cap; bool update_bg_model = true; @@ -37,7 +37,8 @@ int main(int argc, const char** argv) cap.open(0); else cap.open(file.c_str()); - parser.printParams(); + + parser.printMessage(); if( !cap.isOpened() ) { diff --git a/samples/cpp/brief_match_test.cpp b/samples/cpp/brief_match_test.cpp index 9223f21..b4c81ee 100644 --- a/samples/cpp/brief_match_test.cpp +++ b/samples/cpp/brief_match_test.cpp @@ -53,8 +53,8 @@ static void help() const char* keys = { - "{1| |box.png |the first image}" - "{2| |box_in_scene.png|the second image}" + "{@first_image | box.png | the first image}" + "{@second_image | box_in_scene.png | the second image}" }; int main(int argc, const char ** argv) @@ -62,8 +62,8 @@ int main(int argc, const char ** argv) help(); CommandLineParser parser(argc, argv, keys); - string im1_name = parser.get("1"); - string im2_name = parser.get("2"); + string im1_name = parser.get(1); + string im2_name = parser.get(2); Mat im1 = imread(im1_name, CV_LOAD_IMAGE_GRAYSCALE); Mat im2 = imread(im2_name, CV_LOAD_IMAGE_GRAYSCALE); @@ -72,7 +72,7 @@ int main(int argc, const char ** argv) { cout << "could not open one of the images..." << endl; cout << "the cmd parameters have next current value: " << endl; - parser.printParams(); + parser.printMessage(); return 1; } diff --git a/samples/cpp/camshiftdemo.cpp b/samples/cpp/camshiftdemo.cpp index 0b17239..f9f393f 100644 --- a/samples/cpp/camshiftdemo.cpp +++ b/samples/cpp/camshiftdemo.cpp @@ -64,7 +64,7 @@ static void help() const char* keys = { - "{1| | 0 | camera number}" + "{@camera_number| 0 | camera number}" }; int main( int argc, const char** argv ) @@ -77,7 +77,7 @@ int main( int argc, const char** argv ) float hranges[] = {0,180}; const float* phranges = hranges; CommandLineParser parser(argc, argv, keys); - int camNum = parser.get("1"); + int camNum = parser.get(1); cap.open(camNum); @@ -86,7 +86,7 @@ int main( int argc, const char** argv ) help(); cout << "***Could not initialize capturing...***\n"; cout << "Current parameter's value: \n"; - parser.printParams(); + parser.printMessage(); return -1; } diff --git a/samples/cpp/chamfer.cpp b/samples/cpp/chamfer.cpp index 4be87cf..906c954 100644 --- a/samples/cpp/chamfer.cpp +++ b/samples/cpp/chamfer.cpp @@ -19,8 +19,8 @@ static void help() const char* keys = { - "{1| |logo_in_clutter.png|image edge map }" - "{2| |logo.png |template edge map}" + "{@logo1 |logo_in_clutter.png |image edge map }" + "{@logo2 |logo.png |template edge map}" }; int main( int argc, const char** argv ) @@ -29,8 +29,8 @@ int main( int argc, const char** argv ) help(); CommandLineParser parser(argc, argv, keys); - string image = parser.get("1"); - string templ = parser.get("2"); + string image = parser.get(1); + string templ = parser.get(2); Mat img = imread(image.c_str(), 0); Mat tpl = imread(templ.c_str(), 0); diff --git a/samples/cpp/connected_components.cpp b/samples/cpp/connected_components.cpp index b83660d..c915bcd 100644 --- a/samples/cpp/connected_components.cpp +++ b/samples/cpp/connected_components.cpp @@ -45,14 +45,14 @@ static void help() const char* keys = { - "{1| |stuff.jpg|image for converting to a grayscale}" + "{@image |stuff.jpg|image for converting to a grayscale}" }; int main( int argc, const char** argv ) { help(); CommandLineParser parser(argc, argv, keys); - string inputImage = parser.get("1"); + string inputImage = parser.get(1); img = imread(inputImage.c_str(), 0); if(img.empty()) diff --git a/samples/cpp/demhist.cpp b/samples/cpp/demhist.cpp index 59ecf25..d982ecb 100644 --- a/samples/cpp/demhist.cpp +++ b/samples/cpp/demhist.cpp @@ -62,7 +62,7 @@ static void help() const char* keys = { - "{1| |baboon.jpg|input image file}" + "{@image|baboon.jpg|input image file}" }; int main( int argc, const char** argv ) @@ -70,7 +70,7 @@ int main( int argc, const char** argv ) help(); CommandLineParser parser(argc, argv, keys); - string inputImage = parser.get("1"); + string inputImage = parser.get(1); // Load the source image. HighGUI use. image = imread( inputImage, 0 ); diff --git a/samples/cpp/dft.cpp b/samples/cpp/dft.cpp index dbbc2cc..62dba20 100644 --- a/samples/cpp/dft.cpp +++ b/samples/cpp/dft.cpp @@ -17,14 +17,14 @@ static void help() const char* keys = { - "{1| |lena.jpg|input image file}" + "{@image|lena.jpg|input image file}" }; int main(int argc, const char ** argv) { help(); CommandLineParser parser(argc, argv, keys); - string filename = parser.get("1"); + string filename = parser.get(1); Mat img = imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE); if( img.empty() ) diff --git a/samples/cpp/distrans.cpp b/samples/cpp/distrans.cpp index 4e3c3a2..5e80577 100644 --- a/samples/cpp/distrans.cpp +++ b/samples/cpp/distrans.cpp @@ -104,14 +104,14 @@ static void help() const char* keys = { - "{1| |stuff.jpg|input image file}" + "{@image |stuff.jpg|input image file}" }; int main( int argc, const char** argv ) { help(); CommandLineParser parser(argc, argv, keys); - string filename = parser.get("1"); + string filename = parser.get(1); gray = imread(filename.c_str(), 0); if(gray.empty()) { diff --git a/samples/cpp/edge.cpp b/samples/cpp/edge.cpp index 6ff30a2..8deda89 100644 --- a/samples/cpp/edge.cpp +++ b/samples/cpp/edge.cpp @@ -31,7 +31,7 @@ static void help() const char* keys = { - "{1| |fruits.jpg|input image name}" + "{@image |fruits.jpg|input image name}" }; int main( int argc, const char** argv ) @@ -39,7 +39,7 @@ int main( int argc, const char** argv ) help(); CommandLineParser parser(argc, argv, keys); - string filename = parser.get("1"); + string filename = parser.get(1); image = imread(filename, 1); if(image.empty()) diff --git a/samples/cpp/opencv_version.cpp b/samples/cpp/opencv_version.cpp index 5eb4bcc..635f191 100644 --- a/samples/cpp/opencv_version.cpp +++ b/samples/cpp/opencv_version.cpp @@ -3,19 +3,23 @@ const char* keys = { - "{ b |build |false | print complete build info }" - "{ h |help |false | print this help }" + "{ b build | | print complete build info }" + "{ h help | | print this help }" }; int main(int argc, const char* argv[]) { cv::CommandLineParser parser(argc, argv, keys); - if (parser.get("help")) + if (parser.has("help")) { - parser.printParams(); + parser.printMessage(); } - else if (parser.get("build")) + else if (!parser.check()) + { + parser.printErrors(); + } + else if (parser.has("build")) { std::cout << cv::getBuildInformation() << std::endl; } @@ -25,4 +29,4 @@ int main(int argc, const char* argv[]) } return 0; -} \ No newline at end of file +} diff --git a/samples/cpp/point_cloud.cpp b/samples/cpp/point_cloud.cpp index a9dda17..998fafc 100644 --- a/samples/cpp/point_cloud.cpp +++ b/samples/cpp/point_cloud.cpp @@ -64,20 +64,19 @@ static void openGlDrawCallback(void* userdata) int main(int argc, const char* argv[]) { const char* keys = - "{ l | left | | left image file name }" - "{ r | right | | right image file name }" - "{ i | intrinsic | | intrinsic camera parameters file name }" - "{ e | extrinsic | | extrinsic camera parameters file name }" - "{ d | ndisp | 256 | number of disparities }" - "{ s | scale | 1.0 | scale factor for point cloud }" - "{ h | help | false | print help message }"; + "{ l left | | left image file name }" + "{ r right | | right image file name }" + "{ i intrinsic | | intrinsic camera parameters file name }" + "{ e extrinsic | | extrinsic camera parameters file name }" + "{ d ndisp | 256 | number of disparities }" + "{ s scale | 1.0 | scale factor for point cloud }" + "{ h help | | print help message }"; CommandLineParser cmd(argc, argv, keys); - if (cmd.get("help")) + if (cmd.has("help")) { - cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); return 0; } @@ -88,11 +87,18 @@ int main(int argc, const char* argv[]) int ndisp = cmd.get("ndisp"); double scale = cmd.get("scale"); + if (!cmd.check()) + { + cmd.printErrors(); + return 0; + } + + if (left.empty() || right.empty()) { cout << "Missed input images" << endl; cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); return 0; } @@ -100,7 +106,7 @@ int main(int argc, const char* argv[]) { cout << "Boss camera parameters must be specified" << endl; cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); return 0; } diff --git a/samples/cpp/videostab.cpp b/samples/cpp/videostab.cpp index 7a0ef56..ee5bd1f 100644 --- a/samples/cpp/videostab.cpp +++ b/samples/cpp/videostab.cpp @@ -281,56 +281,56 @@ int main(int argc, const char **argv) try { const char *keys = - "{ 1 | | | | }" - "{ m | model | affine | }" - "{ lp | lin-prog-motion-est | no | }" - "{ | subset | auto | }" - "{ | thresh | auto | }" - "{ | outlier-ratio | 0.5 | }" - "{ | min-inlier-ratio | 0.1 | }" - "{ | nkps | 1000 | }" - "{ | extra-kps | 0 | }" - "{ | local-outlier-rejection | no | }" - "{ sm | save-motions | no | }" - "{ lm | load-motions | no | }" - "{ r | radius | 15 | }" - "{ | stdev | auto | }" - "{ lps | lin-prog-stab | no | }" - "{ | lps-trim-ratio | auto | }" - "{ | lps-w1 | 1 | }" - "{ | lps-w2 | 10 | }" - "{ | lps-w3 | 100 | }" - "{ | lps-w4 | 100 | }" - "{ | deblur | no | }" - "{ | deblur-sens | 0.1 | }" - "{ et | est-trim | yes | }" - "{ t | trim-ratio | 0.1 | }" - "{ ic | incl-constr | no | }" - "{ bm | border-mode | replicate | }" - "{ | mosaic | no | }" - "{ ms | mosaic-stdev | 10.0 | }" - "{ mi | motion-inpaint | no | }" - "{ | mi-dist-thresh | 5.0 | }" - "{ ci | color-inpaint | no | }" - "{ | ci-radius | 2 | }" - "{ ws | wobble-suppress | no | }" - "{ | ws-period | 30 | }" - "{ | ws-model | homography | }" - "{ | ws-subset | auto | }" - "{ | ws-thresh | auto | }" - "{ | ws-outlier-ratio | 0.5 | }" - "{ | ws-min-inlier-ratio | 0.1 | }" - "{ | ws-nkps | 1000 | }" - "{ | ws-extra-kps | 0 | }" - "{ | ws-local-outlier-rejection | no | }" - "{ | ws-lp | no | }" - "{ sm2 | save-motions2 | no | }" - "{ lm2 | load-motions2 | no | }" - "{ gpu | | no }" - "{ o | output | stabilized.avi | }" - "{ | fps | auto | }" - "{ q | quiet | false | }" - "{ h | help | false | }"; + "{ @1 | | }" + "{ m model | affine | }" + "{ lp lin-prog-motion-est | no | }" + "{ subset | auto | }" + "{ thresh | auto | }" + "{ outlier-ratio | 0.5 | }" + "{ min-inlier-ratio | 0.1 | }" + "{ nkps | 1000 | }" + "{ extra-kps | 0 | }" + "{ local-outlier-rejection | no | }" + "{ sm save-motions | no | }" + "{ lm load-motions | no | }" + "{ r radius | 15 | }" + "{ stdev | auto | }" + "{ lps lin-prog-stab | no | }" + "{ lps-trim-ratio | auto | }" + "{ lps-w1 | 1 | }" + "{ lps-w2 | 10 | }" + "{ lps-w3 | 100 | }" + "{ lps-w4 | 100 | }" + "{ deblur | no | }" + "{ deblur-sens | 0.1 | }" + "{ et est-trim | yes | }" + "{ t trim-ratio | 0.1 | }" + "{ ic incl-constr | no | }" + "{ bm border-mode | replicate | }" + "{ mosaic | no | }" + "{ ms mosaic-stdev | 10.0 | }" + "{ mi motion-inpaint | no | }" + "{ mi-dist-thresh | 5.0 | }" + "{ ci color-inpaint | no | }" + "{ ci-radius | 2 | }" + "{ ws wobble-suppress | no | }" + "{ ws-period | 30 | }" + "{ ws-model | homography | }" + "{ ws-subset | auto | }" + "{ ws-thresh | auto | }" + "{ ws-outlier-ratio | 0.5 | }" + "{ ws-min-inlier-ratio | 0.1 | }" + "{ ws-nkps | 1000 | }" + "{ ws-extra-kps | 0 | }" + "{ ws-local-outlier-rejection | no | }" + "{ ws-lp | no | }" + "{ sm2 save-motions2 | no | }" + "{ lm2 load-motions2 | no | }" + "{ gpu | no | }" + "{ o output | stabilized.avi | }" + "{ fps | auto | }" + "{ q quiet | | }" + "{ h help | | }"; CommandLineParser cmd(argc, argv, keys); // parse command arguments diff --git a/samples/gpu/bgfg_segm.cpp b/samples/gpu/bgfg_segm.cpp index 4e4c520..9456b15 100644 --- a/samples/gpu/bgfg_segm.cpp +++ b/samples/gpu/bgfg_segm.cpp @@ -21,20 +21,19 @@ enum Method int main(int argc, const char** argv) { cv::CommandLineParser cmd(argc, argv, - "{ c | camera | false | use camera }" - "{ f | file | 768x576.avi | input video file }" - "{ m | method | mog | method (fgd, mog, mog2, vibe, gmg) }" - "{ h | help | false | print help message }"); + "{ c camera | | use camera }" + "{ f file | 768x576.avi | input video file }" + "{ m method | mog | method (fgd, mog, mog2, vibe, gmg) }" + "{ h help | | print help message }"); - if (cmd.get("help")) + if (cmd.has("help") || !cmd.check()) { - cout << "Usage : bgfg_segm [options]" << endl; - cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); + cmd.printErrors(); return 0; } - bool useCamera = cmd.get("camera"); + bool useCamera = cmd.has("camera"); string file = cmd.get("file"); string method = cmd.get("method"); diff --git a/samples/gpu/brox_optical_flow.cpp b/samples/gpu/brox_optical_flow.cpp index 8ff0df4..76339c9 100644 --- a/samples/gpu/brox_optical_flow.cpp +++ b/samples/gpu/brox_optical_flow.cpp @@ -25,24 +25,23 @@ int main(int argc, const char* argv[]) try { const char* keys = - "{ h | help | false | print help message }" - "{ l | left | | specify left image }" - "{ r | right | | specify right image }" - "{ s | scale | 0.8 | set pyramid scale factor }" - "{ a | alpha | 0.197 | set alpha }" - "{ g | gamma | 50.0 | set gamma }" - "{ i | inner | 10 | set number of inner iterations }" - "{ o | outer | 77 | set number of outer iterations }" - "{ si | solver | 10 | set number of basic solver iterations }" - "{ t | time_step | 0.1 | set frame interpolation time step }"; + "{ h help | | print help message }" + "{ l left | | specify left image }" + "{ r right | | specify right image }" + "{ s scale | 0.8 | set pyramid scale factor }" + "{ a alpha | 0.197 | set alpha }" + "{ g gamma | 50.0 | set gamma }" + "{ i inner | 10 | set number of inner iterations }" + "{ o outer | 77 | set number of outer iterations }" + "{ si solver | 10 | set number of basic solver iterations }" + "{ t time_step | 0.1 | set frame interpolation time step }"; CommandLineParser cmd(argc, argv, keys); - if (cmd.get("help")) + if (cmd.has("help") || !cmd.check()) { - cout << "Usage: brox_optical_flow [options]" << endl; - cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); + cmd.printErrors(); return 0; } diff --git a/samples/gpu/farneback_optical_flow.cpp b/samples/gpu/farneback_optical_flow.cpp index e33c07e..77ee49e 100644 --- a/samples/gpu/farneback_optical_flow.cpp +++ b/samples/gpu/farneback_optical_flow.cpp @@ -43,19 +43,19 @@ static void colorizeFlow(const Mat &u, const Mat &v, Mat &dst) int main(int argc, char **argv) { CommandLineParser cmd(argc, argv, - "{ l | left | | specify left image }" - "{ r | right | | specify right image }" - "{ h | help | false | print help message }"); + "{ l left | | specify left image }" + "{ r right | | specify right image }" + "{ h help | | print help message }"); - if (cmd.get("help")) + cmd.about("Farneback's optical flow sample."); + if (cmd.has("help") || !cmd.check()) { - cout << "Farneback's optical flow sample.\n\n" - << "Usage: farneback_optical_flow_gpu [arguments]\n\n" - << "Arguments:\n"; - cmd.printParams(); + cmd.printMessage(); + cmd.printErrors(); return 0; } + string pathL = cmd.get("left"); string pathR = cmd.get("right"); if (pathL.empty()) cout << "Specify left image path\n"; diff --git a/samples/gpu/performance/performance.cpp b/samples/gpu/performance/performance.cpp index 1cb9176..2f5448b 100644 --- a/samples/gpu/performance/performance.cpp +++ b/samples/gpu/performance/performance.cpp @@ -165,22 +165,23 @@ int main(int argc, const char* argv[]) redirectError(cvErrorCallback); const char* keys = - "{ h | help | false | print help message }" - "{ f | filter | | filter for test }" - "{ w | workdir | | set working directory }" - "{ l | list | false | show all tests }" - "{ d | device | 0 | device id }" - "{ i | iters | 10 | iteration count }"; + "{ h help | | print help message }" + "{ f filter | | filter for test }" + "{ w workdir | | set working directory }" + "{ l list | | show all tests }" + "{ d device | 0 | device id }" + "{ i iters | 10 | iteration count }"; CommandLineParser cmd(argc, argv, keys); - if (cmd.get("help")) + if (cmd.has("help") || !cmd.check()) { - cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); + cmd.printErrors(); return 0; } + int device = cmd.get("device"); if (device < 0 || device >= num_devices) { @@ -198,7 +199,7 @@ int main(int argc, const char* argv[]) string filter = cmd.get("filter"); string workdir = cmd.get("workdir"); - bool list = cmd.get("list"); + bool list = cmd.has("list"); int iters = cmd.get("iters"); if (!filter.empty()) diff --git a/samples/gpu/pyrlk_optical_flow.cpp b/samples/gpu/pyrlk_optical_flow.cpp index 5bff8f9..5ebf859 100644 --- a/samples/gpu/pyrlk_optical_flow.cpp +++ b/samples/gpu/pyrlk_optical_flow.cpp @@ -152,23 +152,22 @@ static void getFlowField(const Mat& u, const Mat& v, Mat& flowField) int main(int argc, const char* argv[]) { const char* keys = - "{ h | help | false | print help message }" - "{ l | left | | specify left image }" - "{ r | right | | specify right image }" - "{ gray | gray | false | use grayscale sources [PyrLK Sparse] }" - "{ win_size | win_size | 21 | specify windows size [PyrLK] }" - "{ max_level | max_level | 3 | specify max level [PyrLK] }" - "{ iters | iters | 30 | specify iterations count [PyrLK] }" - "{ points | points | 4000 | specify points count [GoodFeatureToTrack] }" - "{ min_dist | min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }"; + "{ h help | | print help message }" + "{ l left | | specify left image }" + "{ r right | | specify right image }" + "{ gray | | use grayscale sources [PyrLK Sparse] }" + "{ win_size | 21 | specify windows size [PyrLK] }" + "{ max_level | 3 | specify max level [PyrLK] }" + "{ iters | 30 | specify iterations count [PyrLK] }" + "{ points | 4000 | specify points count [GoodFeatureToTrack] }" + "{ min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }"; CommandLineParser cmd(argc, argv, keys); - if (cmd.get("help")) + if (cmd.has("help") || !cmd.check()) { - cout << "Usage: pyrlk_optical_flow [options]" << endl; - cout << "Avaible options:" << endl; - cmd.printParams(); + cmd.printMessage(); + cmd.printErrors(); return 0; } @@ -181,7 +180,7 @@ int main(int argc, const char* argv[]) return -1; } - bool useGray = cmd.get("gray"); + bool useGray = cmd.has("gray"); int winSize = cmd.get("win_size"); int maxLevel = cmd.get("max_level"); int iters = cmd.get("iters");