[][src]Struct opencv::core::CommandLineParser

pub struct CommandLineParser { /* fields omitted */ }

Designed for command line parsing

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>("fps");
   String path = parser.get<String>("path");
 
   use_time_stamp = parser.has("timestamp");
 
   String img1 = parser.get<String>(0);
   String img2 = parser.get<String>(1);
 
   int repeat = parser.get<int>(2);
 
   if (!parser.check())
   {
       parser.printErrors();
       return 0;
   }

Keys syntax

The keys parameter is a string containing several blocks, each one is enclosed in curly braces and describes one argument. Each argument contains three parts separated by the | symbol:

-# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the @ symbol) -# default value will be used if the argument was not provided (can be empty) -# help message (can be empty)

For example:

   const String keys =
       "{help h usage ? |      | print this message   }"
       "{@image1        |      | image1 for compare   }"
       "{@image2        |<none>| 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       }"
       ;
}

Note that there are no default values for help and timestamp so we can check their presence using the has() method. Arguments with default values are considered to be always present. Use the get() method in these cases to check their actual value instead.

String keys like get<String>("@image1") return the empty string "" by default - even with an empty default value. Use the special <none> default value to enforce that the returned string must not be empty. (like in get<String>("@image2"))

Usage

For the described keys:

   $ ./app -N=200 1.png 2.jpg 19 -ts
 
   $ ./app -fps=aaa
   ERRORS:
   Parameter "fps": can not convert: [aaa] to [double]

Implementations

impl CommandLineParser[src]

impl CommandLineParser[src]

pub fn new(argc: i32, argv: &[&str], keys: &str) -> Result<CommandLineParser>[src]

Constructor

Initializes command line parser object

Parameters

  • argc: number of command line arguments (from main())
  • argv: array of command line arguments (from main())
  • keys: string describing acceptable command line parameters (see class description for syntax)

pub fn copy(parser: &CommandLineParser) -> Result<CommandLineParser>[src]

Copy constructor

Trait Implementations

impl Boxed for CommandLineParser[src]

impl CommandLineParserTrait for CommandLineParser[src]

impl Drop for CommandLineParser[src]

impl Send for CommandLineParser[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.