[−][src]Struct opencv::core::CommandLineParser
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]
pub fn as_raw_CommandLineParser(&self) -> *const c_void
[src]
pub fn as_raw_mut_CommandLineParser(&mut self) -> *mut c_void
[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]
pub unsafe fn from_raw(ptr: *mut c_void) -> Self
[src]
pub fn into_raw(self) -> *mut c_void
[src]
pub fn as_raw(&self) -> *const c_void
[src]
pub fn as_raw_mut(&mut self) -> *mut c_void
[src]
impl CommandLineParserTrait for CommandLineParser
[src]
pub fn as_raw_CommandLineParser(&self) -> *const c_void
[src]
pub fn as_raw_mut_CommandLineParser(&mut self) -> *mut c_void
[src]
pub fn get_path_to_application(&self) -> Result<String>
[src]
pub fn has(&self, name: &str) -> Result<bool>
[src]
pub fn check(&self) -> Result<bool>
[src]
pub fn about(&mut self, message: &str) -> Result<()>
[src]
pub fn print_message(&self) -> Result<()>
[src]
pub fn print_errors(&self) -> Result<()>
[src]
impl Drop for CommandLineParser
[src]
impl Send for CommandLineParser
[src]
Auto Trait Implementations
impl RefUnwindSafe for CommandLineParser
[src]
impl !Sync for CommandLineParser
[src]
impl Unpin for CommandLineParser
[src]
impl UnwindSafe for CommandLineParser
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,