add new version of CommandLineParser. add empty docs
authorAoD314 <morozov.andrey.vmk@gmail.com>
Fri, 7 Sep 2012 09:24:48 +0000 (13:24 +0400)
committerAoD314 <morozov.andrey.vmk@gmail.com>
Fri, 7 Sep 2012 09:24:48 +0000 (13:24 +0400)
26 files changed:
modules/core/doc/command_line_parser.rst [new file with mode: 0644]
modules/core/doc/core.rst
modules/core/include/opencv2/core/core.hpp
modules/core/src/cmdparser.cpp [deleted file]
modules/core/src/command_line_parser.cpp [new file with mode: 0644]
modules/gpu/perf/main.cpp
modules/gpu/test/main.cpp
modules/ts/src/ts_perf.cpp
samples/c/bgfg_codebook.cpp
samples/cpp/bgfg_segm.cpp
samples/cpp/brief_match_test.cpp
samples/cpp/camshiftdemo.cpp
samples/cpp/chamfer.cpp
samples/cpp/connected_components.cpp
samples/cpp/demhist.cpp
samples/cpp/dft.cpp
samples/cpp/distrans.cpp
samples/cpp/edge.cpp
samples/cpp/opencv_version.cpp
samples/cpp/point_cloud.cpp
samples/cpp/videostab.cpp
samples/gpu/bgfg_segm.cpp
samples/gpu/brox_optical_flow.cpp
samples/gpu/farneback_optical_flow.cpp
samples/gpu/performance/performance.cpp
samples/gpu/pyrlk_optical_flow.cpp

diff --git a/modules/core/doc/command_line_parser.rst b/modules/core/doc/command_line_parser.rst
new file mode 100644 (file)
index 0000000..5f0e512
--- /dev/null
@@ -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<T>(const std::string& name, bool space_delete = true)
+
+        :param name: 
+        :param space_delete: 
+
+    .. ocv:function:: T CommandLineParser::get<T>(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<int>("N");
+    double fps = parser.get<double>parser("fps");
+    std::string path = parser.get<std::string>("path");
+
+    use_time_stamp = parserer.has("timestamp");
+
+    std::string img1 = parser.get<string>(1);
+    std::string img2 = parser.get<string>(2);
+
+    int repeat = parser.get<int>(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]
+
index 7eb4e3e..90caeeb 100644 (file)
@@ -6,6 +6,7 @@ core. The Core Functionality
     :maxdepth: 2
 
     basic_structures
+    command_line_parser
     old_basic_structures
     dynamic_structures
     operations_on_arrays
index f03f21b..2496c80 100644 (file)
@@ -4505,113 +4505,143 @@ template<> struct ParamType<Algorithm>
     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  <If a key with '--' must has an argument\n"
-           "                  you have to assign it through '=' sign.> \n"
-           "<If the key with '--' doesn't have any argument, it means that it is a bool key>\n"
-           "    -key2=arg2   <If a key with '-' must has an argument \n"
-           "                  you have to assign it through '=' sign.> \n"
-           "If the key with '-' doesn't have any argument, it means that it is a bool key\n"
-           "    key3                 <This key can't has any parameter> \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<string>(\"s\" or \"string\") will return you first parameter value\n"
-           "    parser.get<string>(\"s\", false or \"string\", false) will return you first parameter value\n"
-           "                                                                without spaces in end and begin\n"
-           "    parser.get<int>(\"d\" or \"digit\") will return you second parameter value.\n"
-           "                    It also works with 'unsigned int', 'double', and 'float' types>\n"
-           "    parser.get<bool>(\"c\" or \"noCamera\") will return you true .\n"
-           "                                If you enter this key in commandline>\n"
-           "                                It return you false otherwise.\n"
-           "    parser.get<string>(\"1\") will return you the first argument without parameter (lena.jpg) \n"
-           "    parser.get<int>(\"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<std::string> keys;
+        int number;
+};
 
-    //! the default constructor
-      CommandLineParser(int argc, const char* const argv[], const char* key_map);
+template <typename T>
+std::string get_type_name() { return "UNKNOW"; }
+
+bool cmp_params(const CommandLineParserParams & p1, const CommandLineParserParams & p2);
+
+template<typename T>
+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<typename _Tp>
-    _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<T>()
+                + 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<std::string, std::vector<std::string> > data;
-    std::string getString(const std::string& name);
+template<> std::string from_str(const std::string & str);
+
+template<typename T>
+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<typename _Tp>
-    _Tp analyzeValue(const std::string& str, bool space_delete=false);
+        std::string getPathToApplication();
 
-    template<typename _Tp>
-    static _Tp getData(const std::string& str)
-    {
-        _Tp res;
-        std::stringstream s1(str);
-        s1 >> res;
-        return res;
-    }
+        template <typename T>
+        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<T>(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<typename _Tp>
-     _Tp fromStringNumber(const std::string& str);//the default conversion function for numbers
+        template <typename T>
+        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<T>(v);
+                    }
+                }
+                error = true;
+                error_message += "Unknown parametes #" + to_str<int>(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<bool>(const std::string& name, bool space_delete);
+        bool check();
 
-template<> CV_EXPORTS
-std::string CommandLineParser::analyzeValue<std::string>(const std::string& str, bool space_delete);
+        void about(std::string message);
 
-template<> CV_EXPORTS
-int CommandLineParser::analyzeValue<int>(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<unsigned int>(const std::string& str, bool space_delete);
+        std::string path_to_app;
+        std::string app_name;
 
-template<> CV_EXPORTS
-uint64 CommandLineParser::analyzeValue<uint64>(const std::string& str, bool space_delete);
+        std::vector<CommandLineParserParams> data;
 
-template<> CV_EXPORTS
-float CommandLineParser::analyzeValue<float>(const std::string& str, bool space_delete);
+        std::vector<std::string> split_range_string(std::string str, char fs, char ss);
+        std::vector<std::string> 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<double>(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 (file)
index d7be054..0000000
+++ /dev/null
@@ -1,384 +0,0 @@
-#include "precomp.hpp"
-
-#include <iostream>
-#include <iomanip>
-
-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  <If a key with '--' must has an argument\n"
-           "                  you have to assign it through '=' sign.> \n"
-           "<If the key with '--' doesn't have any argument, it means that it is a bool key>\n"
-           "    -key2=arg2   <If a key with '-' must has an argument \n"
-           "                  you have to assign it through '=' sign.> \n"
-           "If the key with '-' doesn't have any argument, it means that it is a bool key\n"
-           "    key3                 <This key can't has any parameter> \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<string>(\"s\" or \"string\") will return you first parameter value\n"
-           "    parser.get<string>(\"s\", false or \"string\", false) will return you first parameter value\n"
-           "                                                                without spaces in end and begin\n"
-           "    parser.get<int>(\"d\" or \"digit\") will return you second parameter value.\n"
-           "                    It also works with 'unsigned int', 'double', and 'float' types>\n"
-           "    parser.get<bool>(\"c\" or \"noCamera\") will return you true .\n"
-           "                                If you enter this key in commandline>\n"
-           "                                It return you false otherwise.\n"
-           "    parser.get<string>(\"1\") will return you the first argument without parameter (lena.jpg) \n"
-           "    parser.get<int>(\"2\") will return you the second argument without parameter (10000)\n"
-           "                          It also works with 'unsigned int', 'double', and 'float' types \n"
-           );
-}
-#endif
-
-vector<string> split_string(const string& str, const string& delimiters)
-{
-       vector<string> 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<string> keysVector;
-    std::vector<string> paramVector;
-    std::map<std::string, std::vector<std::string> >::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<std::string, std::vector<std::string> >::iterator it;
-    std::vector<string> 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<std::string, std::vector<std::string> >::iterator it;
-    std::vector<string> 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<typename _Tp>
- _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<std::string, std::vector<std::string> >::iterator it;
-       std::vector<string> 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<bool>(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<std::string>(const std::string& str, bool space_delete)
-{
-    if (space_delete)
-    {
-               return del_space(str);
-    } 
-    return str;
-}
-
-template<>
-int CommandLineParser::analyzeValue<int>(const std::string& str, bool /*space_delete*/)
-{
-    return fromStringNumber<int>(str);
-}
-
-template<>
-unsigned int CommandLineParser::analyzeValue<unsigned int>(const std::string& str, bool /*space_delete*/)
-{
-    return fromStringNumber<unsigned int>(str);
-}
-
-template<>
-uint64 CommandLineParser::analyzeValue<uint64>(const std::string& str, bool /*space_delete*/)
-{
-    return fromStringNumber<uint64>(str);
-}
-
-template<>
-float CommandLineParser::analyzeValue<float>(const std::string& str, bool /*space_delete*/)
-{
-    return fromStringNumber<float>(str);
-}
-
-template<>
-double CommandLineParser::analyzeValue<double>(const std::string& str, bool /*space_delete*/)
-{
-    return fromStringNumber<double>(str);
-}
diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp
new file mode 100644 (file)
index 0000000..dc137e7
--- /dev/null
@@ -0,0 +1,406 @@
+\r
+#include "precomp.hpp"\r
+\r
+#include <iostream>\r
+\r
+namespace cv\r
+{\r
+    bool cmp_params(const CommandLineParserParams & p1, const CommandLineParserParams & p2)\r
+    {\r
+        if (p1.number > p2.number)\r
+            return false;\r
+\r
+        if (p1.number == -1 && p2.number == -1)\r
+        {\r
+            if (p1.keys[0].compare(p2.keys[0]) > 0)\r
+            {\r
+                return false;\r
+            }\r
+        }\r
+\r
+        return true;\r
+    }\r
+\r
+    CommandLineParser::CommandLineParser(int argc, const char * const argv[], const std::string keys)\r
+    {\r
+        // path to application\r
+        size_t pos_s = std::string(argv[0]).find_last_of("/\\");\r
+        if (pos_s == std::string::npos)\r
+        {\r
+            path_to_app = "";\r
+            app_name = std::string(argv[0]);\r
+        }\r
+        else\r
+        {\r
+            path_to_app = std::string(argv[0]).substr(0, pos_s);\r
+            app_name = std::string(argv[0]).substr(pos_s + 1, std::string(argv[0]).length() - pos_s);\r
+        }\r
+\r
+        error = false;\r
+        error_message = "";\r
+\r
+        // parse keys\r
+        std::vector<std::string> k = split_range_string(keys, '{', '}');\r
+\r
+        int jj = 0;\r
+        for (size_t i = 0; i < k.size(); i++)\r
+        {\r
+            std::vector<std::string> l = split_string(k[i], '|', true);\r
+            CommandLineParserParams p;\r
+            p.keys = split_string(l[0]);\r
+            p.def_value = l[1];\r
+            p.help_message = cat_string(l[2]);\r
+            p.number = -1;\r
+            if (p.keys[0][0] == '@')\r
+            {\r
+                p.number = jj;\r
+                jj++;\r
+            }\r
+\r
+            data.push_back(p);\r
+        }\r
+\r
+        // parse argv\r
+        jj = 0;\r
+        for (int i = 1; i < argc; i++)\r
+        {\r
+            std::string s = std::string(argv[i]);\r
+\r
+            if (s.find('=') != std::string::npos && s.find('=') < s.length())\r
+            {\r
+                std::vector<std::string> k_v = split_string(s, '=', true);\r
+                for (int h = 0; h < 2; h++)\r
+                {\r
+                    if (k_v[0][0] == '-')\r
+                        k_v[0] = k_v[0].substr(1, k_v[0].length() -1);\r
+                }\r
+                apply_params(k_v[0], k_v[1]);\r
+            }\r
+            else if (s.length() > 1 && s[0] == '-')\r
+            {\r
+                for (int h = 0; h < 2; h++)\r
+                {\r
+                    if (s[0] == '-')\r
+                        s = s.substr(1, s.length() - 1);\r
+                }\r
+                apply_params(s, "true");\r
+            }\r
+            else if (s[0] != '-')\r
+            {\r
+                apply_params(jj, s);\r
+                jj++;\r
+            }\r
+        }\r
+\r
+        sort_params();\r
+    }\r
+\r
+    void CommandLineParser::about(std::string message)\r
+    {\r
+        about_message = message;\r
+    }\r
+\r
+    void CommandLineParser::apply_params(std::string key, std::string value)\r
+    {\r
+        for (size_t i = 0; i < data.size(); i++)\r
+        {\r
+            for (size_t k = 0; k < data[i].keys.size(); k++)\r
+            {\r
+                if (key.compare(data[i].keys[k]) == 0)\r
+                {\r
+                    data[i].def_value = value;\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    void CommandLineParser::apply_params(int i, std::string value)\r
+    {\r
+        for (size_t j = 0; j < data.size(); j++)\r
+        {\r
+            if (data[j].number == i)\r
+            {\r
+                data[j].def_value = value;\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+    void CommandLineParser::sort_params()\r
+    {\r
+        for (size_t i = 0; i < data.size(); i++)\r
+        {\r
+            sort(data[i].keys.begin(), data[i].keys.end());\r
+        }\r
+\r
+        sort (data.begin(), data.end(), cmp_params);\r
+    }\r
+\r
+    std::string CommandLineParser::cat_string(std::string str)\r
+    {\r
+        while (!str.empty() && str[0] == ' ')\r
+        {\r
+            str = str.substr(1, str.length() - 1);\r
+        }\r
+\r
+        while (!str.empty() && str[str.length() - 1] == ' ')\r
+        {\r
+            str = str.substr(0, str.length() - 1);\r
+        }\r
+\r
+        return str;\r
+    }\r
+\r
+    std::string CommandLineParser::getPathToApplication()\r
+    {\r
+        return path_to_app;\r
+    }\r
+\r
+    bool CommandLineParser::has(const std::string& name)\r
+    {\r
+        for (size_t i = 0; i < data.size(); i++)\r
+        {\r
+            for (size_t j = 0; j < data[i].keys.size(); j++)\r
+            {\r
+                if (name.compare(data[i].keys[j]) == 0 && std::string("true").compare(data[i].def_value) == 0)\r
+                {\r
+                    return true;\r
+                }\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+\r
+    bool CommandLineParser::check()\r
+    {\r
+        return error == false;\r
+    }\r
+\r
+    void CommandLineParser::printErrors()\r
+    {\r
+        if (error)\r
+        {\r
+            std::cout << std::endl << "ERRORS:" << std::endl << error_message << std::endl;\r
+        }\r
+    }\r
+\r
+    void CommandLineParser::printMessage()\r
+    {\r
+        if (about_message != "")\r
+            std::cout << about_message << std::endl;\r
+\r
+        std::cout << "Usage: " << app_name << " [params] ";\r
+\r
+        for (size_t i = 0; i < data.size(); i++)\r
+        {\r
+            if (data[i].number > -1)\r
+            {\r
+                std::string name = data[i].keys[0].substr(1, data[i].keys[0].length() - 1);\r
+                std::cout << name << " ";\r
+            }\r
+        }\r
+\r
+        std::cout << std::endl << std::endl;\r
+\r
+        for (size_t i = 0; i < data.size(); i++)\r
+        {\r
+            if (data[i].number == -1)\r
+            {\r
+                std::cout << "\t";\r
+                for (size_t j = 0; j < data[i].keys.size(); j++)\r
+                {\r
+                    std::string k = data[i].keys[j];\r
+                    if (k.length() > 1)\r
+                    {\r
+                        std::cout << "--";\r
+                    }\r
+                    else\r
+                    {\r
+                        std::cout << "-";\r
+                    }\r
+                    std::cout << k;\r
+\r
+                    if (j != data[i].keys.size() - 1)\r
+                    {\r
+                        std::cout << ", ";\r
+                    }\r
+                }\r
+                std::string dv = cat_string(data[i].def_value);\r
+                if (dv.compare("") != 0)\r
+                {\r
+                    std::cout << " (value:" << dv << ")";\r
+                }\r
+                std::cout << std::endl << "\t\t" << data[i].help_message << std::endl;\r
+            }\r
+        }\r
+        std::cout << std::endl;\r
+\r
+        for (size_t i = 0; i < data.size(); i++)\r
+        {\r
+            if (data[i].number != -1)\r
+            {\r
+                std::cout << "\t";\r
+                std::string k = data[i].keys[0];\r
+                k = k.substr(1, k.length() - 1);\r
+\r
+                std::cout << k;\r
+\r
+                std::string dv = cat_string(data[i].def_value);\r
+                if (dv.compare("") != 0)\r
+                {\r
+                    std::cout << " (value:" << dv << ")";\r
+                }\r
+                std::cout << std::endl << "\t\t" << data[i].help_message << std::endl;\r
+            }\r
+        }\r
+    }\r
+\r
+    std::vector<std::string> CommandLineParser::split_range_string(std::string str, char fs, char ss)\r
+    {\r
+        std::vector<std::string> vec;\r
+        std::string word = "";\r
+        bool begin = false;\r
+\r
+        while (!str.empty())\r
+        {\r
+            if (str[0] == fs)\r
+            {\r
+                if (begin == true)\r
+                {\r
+                    CV_Error(CV_StsParseError,\r
+                             std::string("error in split_range_string(")\r
+                             + str\r
+                             + std::string(", ")\r
+                             + std::string(1, fs)\r
+                             + std::string(", ")\r
+                             + std::string(1, ss)\r
+                             + std::string(")")\r
+                             );\r
+                }\r
+                begin = true;\r
+                word = "";\r
+                str = str.substr(1, str.length() - 1);\r
+            }\r
+\r
+            if (str[0] == ss)\r
+            {\r
+                if (begin == false)\r
+                {\r
+                    CV_Error(CV_StsParseError,\r
+                             std::string("error in split_range_string(")\r
+                             + str\r
+                             + std::string(", ")\r
+                             + std::string(1, fs)\r
+                             + std::string(", ")\r
+                             + std::string(1, ss)\r
+                             + std::string(")")\r
+                             );\r
+                }\r
+                begin = false;\r
+                vec.push_back(word);\r
+            }\r
+\r
+            if (begin == true)\r
+            {\r
+                word += str[0];\r
+            }\r
+            str = str.substr(1, str.length() - 1);\r
+        }\r
+\r
+        if (begin == true)\r
+        {\r
+            CV_Error(CV_StsParseError,\r
+                     std::string("error in split_range_string(")\r
+                     + str\r
+                     + std::string(", ")\r
+                     + std::string(1, fs)\r
+                     + std::string(", ")\r
+                     + std::string(1, ss)\r
+                     + std::string(")")\r
+                     );\r
+        }\r
+\r
+        return vec;\r
+    }\r
+\r
+    std::vector<std::string> CommandLineParser::split_string(std::string str, char symbol, bool create_empty_item)\r
+    {\r
+        std::vector<std::string> vec;\r
+        std::string word = "";\r
+\r
+        while (!str.empty())\r
+        {\r
+            if (str[0] == symbol)\r
+            {\r
+                if (!word.empty() || create_empty_item)\r
+                {\r
+                    vec.push_back(word);\r
+                    word = "";\r
+                }\r
+            }\r
+            else\r
+            {\r
+                word += str[0];\r
+            }\r
+            str = str.substr(1, str.length() - 1);\r
+        }\r
+\r
+        if (word != "" || create_empty_item)\r
+        {\r
+            vec.push_back(word);\r
+        }\r
+\r
+        return vec;\r
+    }\r
+\r
+    #undef clp_get\r
+    #define clp_get(T) template<> T CommandLineParser::get<T>(const std::string& name, bool space_delete);\r
+\r
+    clp_get(int)\r
+    clp_get(unsigned int)\r
+    clp_get(long)\r
+    clp_get(unsigned long)\r
+    clp_get(long long)\r
+    clp_get(unsigned long long)\r
+    clp_get(size_t)\r
+    clp_get(float)\r
+    clp_get(double)\r
+    clp_get(uint64)\r
+    clp_get(int64)\r
+    clp_get(std::string)\r
+\r
+    #undef clp_from_str\r
+    #define clp_from_str(T) template<> T from_str<T>(const std::string & str);\r
+\r
+    clp_from_str(int)\r
+    clp_from_str(unsigned int)\r
+    clp_from_str(long)\r
+    clp_from_str(unsigned long)\r
+    clp_from_str(long long)\r
+    clp_from_str(unsigned long long)\r
+    clp_from_str(size_t)\r
+    clp_from_str(uint64)\r
+    clp_from_str(int64)\r
+    clp_from_str(float)\r
+    clp_from_str(double)\r
+\r
+    template<>\r
+    std::string from_str(const std::string & str)\r
+    {\r
+        return str;\r
+    }\r
+\r
+    #undef clp_type_name\r
+    #define clp_type_name(type, name) template<> std::string get_type_name<type>() { return std::string(name);}\r
+\r
+    clp_type_name(int, "int")\r
+    clp_type_name(unsigned int, "unsigned int")\r
+    clp_type_name(long, "long")\r
+    clp_type_name(long long, "long long")\r
+    clp_type_name(unsigned long long, "unsigned long long")\r
+    clp_type_name(size_t, "size_t")\r
+    clp_type_name(float, "float")\r
+    clp_type_name(double, "double")\r
+\r
+}\r
index aadeee9..8d34041 100644 (file)
@@ -73,20 +73,32 @@ void printCudaInfo()
 \r
 int main(int argc, char** argv)\r
 {\r
-    CommandLineParser cmd(argc, (const char**) argv,\r
-        "{ print_info_only | print_info_only | false | Print information about system and exit }"\r
-        "{ device | device | 0 | Device on which tests will be executed }"\r
-        "{ cpu | cpu | false | Run tests on cpu }"\r
-    );\r
+    const std::string keys =\r
+            "{ h help ? |   | Print help}"\r
+            "{ i info   |   | Print information about system and exit }"\r
+            "{ device   | 0 | Device on which tests will be executed }"\r
+            "{ cpu      |   | Run tests on cpu }"\r
+            ;\r
+\r
+    CommandLineParser cmd(argc, (const char**) argv, keys);\r
+\r
+    if (cmd.has("help"))\r
+    {\r
+        cmd.printMessage();\r
+        return 0;\r
+    }\r
 \r
     printOsInfo();\r
     printCudaInfo();\r
 \r
-    if (cmd.get<bool>("print_info_only"))\r
+\r
+    if (cmd.has("info"))\r
+    {\r
         return 0;\r
+    }\r
 \r
     int device = cmd.get<int>("device");\r
-    bool cpu = cmd.get<bool>("cpu");\r
+    bool cpu   = cmd.has("cpu");\r
 #ifndef HAVE_CUDA\r
     cpu = true;\r
 #endif\r
index 8f216c9..2e1edf0 100644 (file)
@@ -118,17 +118,28 @@ int main(int argc, char** argv)
 {\r
     try\r
     {\r
-        CommandLineParser cmd(argc, (const char**)argv,\r
-            "{ print_info_only | print_info_only | false | Print information about system and exit }"\r
-            "{ device | device | -1 | Device on which tests will be executed (-1 means all devices) }"\r
-            "{ nvtest_output_level | nvtest_output_level | compact | NVidia test verbosity level }"\r
-        );\r
+        const std::string keys =\r
+                "{ h help ?            |         | Print help}"\r
+                "{ i info              |         | Print information about system and exit }"\r
+                "{ device              | -1      | Device on which tests will be executed (-1 means all devices) }"\r
+                "{ nvtest_output_level | compact | NVidia test verbosity level (none, compact, full) }"\r
+                ;\r
+\r
+        CommandLineParser cmd(argc, (const char**)argv, keys);\r
+\r
+        if (cmd.has("help"))\r
+        {\r
+            cmd.printMessage();\r
+            return 0;\r
+        }\r
 \r
         printOsInfo();\r
         printCudaInfo();\r
 \r
-        if (cmd.get<bool>("print_info_only"))\r
+        if (cmd.has("info"))\r
+        {\r
             return 0;\r
+        }\r
 \r
         int device = cmd.get<int>("device");\r
         if (device < 0)\r
index cd389f1..0bb5d9c 100644 (file)
@@ -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<double>("perf_max_outliers")));
-    param_min_samples  = std::max(1u, args.get<unsigned int>("perf_min_samples"));
+    if (args.has("help"))
+    {
+        args.printMessage();
+        return;
+    }
+
+    param_max_outliers  = std::min(100., std::max(0., args.get<double>("perf_max_outliers")));
+    param_min_samples   = std::max(1u, args.get<unsigned int>("perf_min_samples"));
     param_max_deviation = std::max(0., args.get<double>("perf_max_deviation"));
-    param_seed = args.get<uint64>("perf_seed");
-    param_time_limit = std::max(0., args.get<double>("perf_time_limit"));
+    param_seed          = args.get<unsigned long long>("perf_seed");
+    param_time_limit    = std::max(0., args.get<double>("perf_time_limit"));
     param_force_samples = args.get<unsigned int>("perf_force_samples");
-    param_write_sanity = args.get<bool>("perf_write_sanity");
+    param_write_sanity  = args.has("perf_write_sanity");
     param_tbb_nthreads  = args.get<int>("perf_tbb_nthreads");
 #ifdef ANDROID
-    param_affinity_mask = args.get<int>("perf_affinity_mask");
-    log_power_checkpoints = args.get<bool>("perf_log_power_checkpoints");
+    param_affinity_mask   = args.get<int>("perf_affinity_mask");
+    log_power_checkpoints = args.has("perf_log_power_checkpoints");
 #endif
 
-    if (args.get<bool>("help"))
+    if (!args.check())
     {
-        args.printParams();
-        printf("\n\n");
+        args.printErrors();
         return;
     }
 
index 2b15728..3054e99 100644 (file)
@@ -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<int>("nf");
-    bool useCamera = parser.get<bool>("c");
+    bool useCamera = parser.has("c");
     string filename = parser.get<string>("mf");
     IplImage* rawImage = 0, *yuvImage = 0; //yuvImage is for codebook method
     IplImage *ImaskCodeBook = 0,*ImaskCodeBookCC = 0;
index ffb2382..72566ea 100644 (file)
@@ -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<bool>("camera");
+    bool useCamera = parser.has("camera");
        string file = parser.get<string>("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() )
     {
index 9223f21..b4c81ee 100644 (file)
@@ -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<string>("1");
-  string im2_name = parser.get<string>("2");
+  string im1_name = parser.get<string>(1);
+  string im2_name = parser.get<string>(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;
   }
 
index 0b17239..f9f393f 100644 (file)
@@ -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<int>("1");
+    int camNum = parser.get<int>(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;
     }
 
index 4be87cf..906c954 100644 (file)
@@ -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<string>("1");
-    string templ = parser.get<string>("2");
+    string image = parser.get<string>(1);
+    string templ = parser.get<string>(2);
     Mat img = imread(image.c_str(), 0);
     Mat tpl = imread(templ.c_str(), 0);
 
index b83660d..c915bcd 100644 (file)
@@ -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<string>("1");
+    string inputImage = parser.get<string>(1);
     img = imread(inputImage.c_str(), 0);
 
     if(img.empty())
index 59ecf25..d982ecb 100644 (file)
@@ -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<string>("1");
+    string inputImage = parser.get<string>(1);
 
     // Load the source image. HighGUI use.
     image = imread( inputImage, 0 );
index dbbc2cc..62dba20 100644 (file)
@@ -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<string>("1");
+    string filename = parser.get<string>(1);
 
     Mat img = imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
     if( img.empty() )
index 4e3c3a2..5e80577 100644 (file)
@@ -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<string>("1");
+    string filename = parser.get<string>(1);
     gray = imread(filename.c_str(), 0);
     if(gray.empty())
     {
index 6ff30a2..8deda89 100644 (file)
@@ -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<string>("1");
+    string filename = parser.get<string>(1);
 
     image = imread(filename, 1);
     if(image.empty())
index 5eb4bcc..635f191 100644 (file)
@@ -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<bool>("help"))
+    if (parser.has("help"))
     {
-        parser.printParams();
+        parser.printMessage();
     }
-    else if (parser.get<bool>("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
+}
index a9dda17..998fafc 100644 (file)
@@ -64,20 +64,19 @@ static void openGlDrawCallback(void* userdata)
 int main(int argc, const char* argv[])\r
 {\r
     const char* keys =\r
-       "{ l left      |       | left image file name }"\r
-       "{ r right     |       | right image file name }"\r
-       "{ i intrinsic |       | intrinsic camera parameters file name }"\r
-       "{ e extrinsic |       | extrinsic camera parameters file name }"\r
-       "{ d ndisp     | 256   | number of disparities }"\r
-       "{ s scale     | 1.0   | scale factor for point cloud }"\r
-       "{ h | help      | false | print help message }";\r
+       "{ l left      |       | left image file name }"\r
+       "{ r right     |       | right image file name }"\r
+       "{ i intrinsic |       | intrinsic camera parameters file name }"\r
+       "{ e extrinsic |       | extrinsic camera parameters file name }"\r
+       "{ d ndisp     | 256   | number of disparities }"\r
+       "{ s scale     | 1.0   | scale factor for point cloud }"\r
+       "{ h help      |       | print help message }";\r
 \r
     CommandLineParser cmd(argc, argv, keys);\r
 \r
-    if (cmd.get<bool>("help"))\r
+    if (cmd.has("help"))\r
     {\r
-        cout << "Avaible options:" << endl;\r
-        cmd.printParams();\r
+        cmd.printMessage();\r
         return 0;\r
     }\r
 \r
@@ -88,11 +87,18 @@ int main(int argc, const char* argv[])
     int ndisp = cmd.get<int>("ndisp");\r
     double scale = cmd.get<double>("scale");\r
 \r
+    if (!cmd.check())\r
+    {\r
+        cmd.printErrors();\r
+        return 0;\r
+    }\r
+\r
+\r
     if (left.empty() || right.empty())\r
     {\r
         cout << "Missed input images" << endl;\r
         cout << "Avaible options:" << endl;\r
-        cmd.printParams();\r
+        cmd.printMessage();\r
         return 0;\r
     }\r
 \r
@@ -100,7 +106,7 @@ int main(int argc, const char* argv[])
     {\r
         cout << "Boss camera parameters must be specified" << endl;\r
         cout << "Avaible options:" << endl;\r
-        cmd.printParams();\r
+        cmd.printMessage();\r
         return 0;\r
     }\r
 \r
index 7a0ef56..ee5bd1f 100644 (file)
@@ -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
index 4e4c520..9456b15 100644 (file)
@@ -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<bool>("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<bool>("camera");
+    bool useCamera = cmd.has("camera");
     string file = cmd.get<string>("file");
     string method = cmd.get<string>("method");
 
index 8ff0df4..76339c9 100644 (file)
@@ -25,24 +25,23 @@ int main(int argc, const char* argv[])
     try\r
     {\r
         const char* keys =\r
-           "{ h  | help      | false | print help message }"\r
-           "{ l  | left      |       | specify left image }"\r
-           "{ r  | right     |       | specify right image }"\r
-           "{ s  | scale     | 0.8   | set pyramid scale factor }"\r
-           "{ a  | alpha     | 0.197 | set alpha }"\r
-           "{ g  | gamma     | 50.0  | set gamma }"\r
-           "{ i  | inner     | 10    | set number of inner iterations }"\r
-           "{ o  | outer     | 77    | set number of outer iterations }"\r
-           "{ si | solver    | 10    | set number of basic solver iterations }"\r
-           "{ t  | time_step | 0.1   | set frame interpolation time step }";\r
+           "{ h   help      |       | print help message }"\r
+           "{ l   left      |       | specify left image }"\r
+           "{ r   right     |       | specify right image }"\r
+           "{ s   scale     | 0.8   | set pyramid scale factor }"\r
+           "{ a   alpha     | 0.197 | set alpha }"\r
+           "{ g   gamma     | 50.0  | set gamma }"\r
+           "{ i   inner     | 10    | set number of inner iterations }"\r
+           "{ o   outer     | 77    | set number of outer iterations }"\r
+           "{ si  solver    | 10    | set number of basic solver iterations }"\r
+           "{ t   time_step | 0.1   | set frame interpolation time step }";\r
 \r
         CommandLineParser cmd(argc, argv, keys);\r
 \r
-        if (cmd.get<bool>("help"))\r
+        if (cmd.has("help") || !cmd.check())\r
         {\r
-            cout << "Usage: brox_optical_flow [options]" << endl;\r
-            cout << "Avaible options:" << endl;\r
-            cmd.printParams();\r
+            cmd.printMessage();\r
+            cmd.printErrors();\r
             return 0;\r
         }\r
 \r
index e33c07e..77ee49e 100644 (file)
@@ -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<bool>("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<string>("left");
     string pathR = cmd.get<string>("right");
     if (pathL.empty()) cout << "Specify left image path\n";
index 1cb9176..2f5448b 100644 (file)
@@ -165,22 +165,23 @@ int main(int argc, const char* argv[])
     redirectError(cvErrorCallback);\r
 \r
     const char* keys =\r
-       "{ h | help    | false | print help message }"\r
-       "{ f | filter  |       | filter for test }"\r
-       "{ w | workdir |       | set working directory }"\r
-       "{ l | list    | false | show all tests }"\r
-       "{ d | device  | 0     | device id }"\r
-       "{ i | iters   | 10    | iteration count }";\r
+       "{ h  help    |       | print help message }"\r
+       "{ f  filter  |       | filter for test }"\r
+       "{ w  workdir |       | set working directory }"\r
+       "{ l  list    |       | show all tests }"\r
+       "{ d  device  | 0     | device id }"\r
+       "{ i  iters   | 10    | iteration count }";\r
 \r
     CommandLineParser cmd(argc, argv, keys);\r
 \r
-    if (cmd.get<bool>("help"))\r
+    if (cmd.has("help") || !cmd.check())\r
     {\r
-        cout << "Avaible options:" << endl;\r
-        cmd.printParams();\r
+        cmd.printMessage();\r
+        cmd.printErrors();\r
         return 0;\r
     }\r
 \r
+\r
     int device = cmd.get<int>("device");\r
     if (device < 0 || device >= num_devices)\r
     {\r
@@ -198,7 +199,7 @@ int main(int argc, const char* argv[])
 \r
     string filter = cmd.get<string>("filter");\r
     string workdir = cmd.get<string>("workdir");\r
-    bool list = cmd.get<bool>("list");\r
+    bool list = cmd.has("list");\r
     int iters = cmd.get<int>("iters");\r
 \r
     if (!filter.empty())\r
index 5bff8f9..5ebf859 100644 (file)
@@ -152,23 +152,22 @@ static void getFlowField(const Mat& u, const Mat& v, Mat& flowField)
 int main(int argc, const char* argv[])\r
 {\r
     const char* keys =\r
-        "{ h            | help           | false | print help message }"\r
-        "{ l            | left           |       | specify left image }"\r
-        "{ r            | right          |       | specify right image }"\r
-        "{ gray         | gray           | false | use grayscale sources [PyrLK Sparse] }"\r
-        "{ win_size     | win_size       | 21    | specify windows size [PyrLK] }"\r
-        "{ max_level    | max_level      | 3     | specify max level [PyrLK] }"\r
-        "{ iters        | iters          | 30    | specify iterations count [PyrLK] }"\r
-        "{ points       | points         | 4000  | specify points count [GoodFeatureToTrack] }"\r
-        "{ min_dist     | min_dist       | 0     | specify minimal distance between points [GoodFeatureToTrack] }";\r
+        "{ h             help   |       | print help message }"\r
+        "{ l             left   |       | specify left image }"\r
+        "{ r             right  |       | specify right image }"\r
+        "{ gray                 |       | use grayscale sources [PyrLK Sparse] }"\r
+        "{ win_size             | 21    | specify windows size [PyrLK] }"\r
+        "{ max_level            | 3     | specify max level [PyrLK] }"\r
+        "{ iters                | 30    | specify iterations count [PyrLK] }"\r
+        "{ points               | 4000  | specify points count [GoodFeatureToTrack] }"\r
+        "{ min_dist             | 0     | specify minimal distance between points [GoodFeatureToTrack] }";\r
 \r
     CommandLineParser cmd(argc, argv, keys);\r
 \r
-    if (cmd.get<bool>("help"))\r
+    if (cmd.has("help") || !cmd.check())\r
     {\r
-        cout << "Usage: pyrlk_optical_flow [options]" << endl;\r
-        cout << "Avaible options:" << endl;\r
-        cmd.printParams();\r
+        cmd.printMessage();\r
+        cmd.printErrors();\r
         return 0;\r
     }\r
 \r
@@ -181,7 +180,7 @@ int main(int argc, const char* argv[])
         return -1;\r
     }\r
 \r
-    bool useGray = cmd.get<bool>("gray");\r
+    bool useGray = cmd.has("gray");\r
     int winSize = cmd.get<int>("win_size");\r
     int maxLevel = cmd.get<int>("max_level");\r
     int iters = cmd.get<int>("iters");\r