2012-09-07 11:24:48 +02:00
|
|
|
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)
|
|
|
|
|
2012-10-17 19:42:09 +02:00
|
|
|
:param argc:
|
|
|
|
:param argv:
|
|
|
|
:param keys:
|
2012-09-07 11:24:48 +02:00
|
|
|
|
|
|
|
.. ocv:function:: T CommandLineParser::get<T>(const std::string& name, bool space_delete = true)
|
|
|
|
|
2012-10-17 19:42:09 +02:00
|
|
|
:param name:
|
|
|
|
:param space_delete:
|
2012-09-07 11:24:48 +02:00
|
|
|
|
|
|
|
.. ocv:function:: T CommandLineParser::get<T>(int index, bool space_delete = true)
|
|
|
|
|
2012-10-17 19:42:09 +02:00
|
|
|
:param index:
|
|
|
|
:param space_delete:
|
2012-09-07 11:24:48 +02:00
|
|
|
|
|
|
|
.. ocv:function:: bool CommandLineParser::has(const std::string& name)
|
|
|
|
|
2012-10-17 19:42:09 +02:00
|
|
|
:param name:
|
2012-09-07 11:24:48 +02:00
|
|
|
|
|
|
|
.. ocv:function:: bool CommandLineParser::check()
|
|
|
|
|
|
|
|
|
|
|
|
.. ocv:function:: void CommandLineParser::about(std::string message)
|
2012-10-17 19:42:09 +02:00
|
|
|
|
|
|
|
:param message:
|
2012-09-07 11:24:48 +02:00
|
|
|
|
|
|
|
.. 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");
|
2012-09-07 15:44:01 +02:00
|
|
|
double fps = parser.get<double>("fps");
|
2012-09-07 11:24:48 +02:00
|
|
|
std::string path = parser.get<std::string>("path");
|
|
|
|
|
2012-09-07 15:44:01 +02:00
|
|
|
use_time_stamp = parser.has("timestamp");
|
2012-09-07 11:24:48 +02:00
|
|
|
|
2012-09-07 15:44:01 +02:00
|
|
|
std::string img1 = parser.get<string>(0);
|
|
|
|
std::string img2 = parser.get<string>(1);
|
2012-09-07 11:24:48 +02:00
|
|
|
|
2012-09-07 15:44:01 +02:00
|
|
|
int repeat = parser.get<int>(2);
|
2012-09-07 11:24:48 +02:00
|
|
|
|
|
|
|
if (!parser.check())
|
|
|
|
{
|
|
|
|
parser.printErrors();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
|
|
|
|
::
|
|
|
|
|
2012-10-17 19:42:09 +02:00
|
|
|
const std::string keys =
|
2012-09-07 11:24:48 +02:00
|
|
|
"{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]
|
|
|
|
|