Struct opencv::core::CommandLineParser
source · pub struct CommandLineParser { /* private fields */ }
Expand description
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:
# Good call (3 positional parameters: image1, image2 and repeat; N is 200, ts is true)
$ ./app -N=200 1.png 2.jpg 19 -ts
# Bad call
$ ./app -fps=aaa
ERRORS:
Parameter "fps": can not convert: [aaa] to [double]
Implementations§
source§impl CommandLineParser
impl CommandLineParser
sourcepub fn new(argc: i32, argv: &[&str], keys: &str) -> Result<CommandLineParser>
pub fn new(argc: i32, argv: &[&str], keys: &str) -> Result<CommandLineParser>
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)
sourcepub fn copy(
parser: &impl CommandLineParserTraitConst
) -> Result<CommandLineParser>
pub fn copy( parser: &impl CommandLineParserTraitConst ) -> Result<CommandLineParser>
Copy constructor
Trait Implementations§
source§impl Boxed for CommandLineParser
impl Boxed for CommandLineParser
source§unsafe fn from_raw(
ptr: <CommandLineParser as OpenCVFromExtern>::ExternReceive
) -> Self
unsafe fn from_raw( ptr: <CommandLineParser as OpenCVFromExtern>::ExternReceive ) -> Self
source§fn into_raw(
self
) -> <CommandLineParser as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw( self ) -> <CommandLineParser as OpenCVTypeExternContainer>::ExternSendMut
source§fn as_raw(&self) -> <CommandLineParser as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <CommandLineParser as OpenCVTypeExternContainer>::ExternSend
source§fn as_raw_mut(
&mut self
) -> <CommandLineParser as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self ) -> <CommandLineParser as OpenCVTypeExternContainer>::ExternSendMut
source§impl CommandLineParserTraitConst for CommandLineParser
impl CommandLineParserTraitConst for CommandLineParser
fn as_raw_CommandLineParser(&self) -> *const c_void
source§fn get_bool(&self, name: &str, space_delete: bool) -> Result<bool>
fn get_bool(&self, name: &str, space_delete: bool) -> Result<bool>
source§fn get_i32(&self, name: &str, space_delete: bool) -> Result<i32>
fn get_i32(&self, name: &str, space_delete: bool) -> Result<i32>
source§fn get_f64(&self, name: &str, space_delete: bool) -> Result<f64>
fn get_f64(&self, name: &str, space_delete: bool) -> Result<f64>
source§fn get_str(&self, name: &str, space_delete: bool) -> Result<String>
fn get_str(&self, name: &str, space_delete: bool) -> Result<String>
source§fn get_u64(&self, name: &str, space_delete: bool) -> Result<u64>
fn get_u64(&self, name: &str, space_delete: bool) -> Result<u64>
source§fn get_bool_idx(&self, index: i32, space_delete: bool) -> Result<bool>
fn get_bool_idx(&self, index: i32, space_delete: bool) -> Result<bool>
source§fn get_bool_idx_def(&self, index: i32) -> Result<bool>
fn get_bool_idx_def(&self, index: i32) -> Result<bool>
source§fn get_i32_idx(&self, index: i32, space_delete: bool) -> Result<i32>
fn get_i32_idx(&self, index: i32, space_delete: bool) -> Result<i32>
source§fn get_i32_idx_def(&self, index: i32) -> Result<i32>
fn get_i32_idx_def(&self, index: i32) -> Result<i32>
source§fn get_f64_idx(&self, index: i32, space_delete: bool) -> Result<f64>
fn get_f64_idx(&self, index: i32, space_delete: bool) -> Result<f64>
source§fn get_f64_idx_def(&self, index: i32) -> Result<f64>
fn get_f64_idx_def(&self, index: i32) -> Result<f64>
source§fn get_str_idx(&self, index: i32, space_delete: bool) -> Result<String>
fn get_str_idx(&self, index: i32, space_delete: bool) -> Result<String>
source§fn get_str_idx_def(&self, index: i32) -> Result<String>
fn get_str_idx_def(&self, index: i32) -> Result<String>
source§fn get_u64_idx(&self, index: i32, space_delete: bool) -> Result<u64>
fn get_u64_idx(&self, index: i32, space_delete: bool) -> Result<u64>
source§fn get_u64_idx_def(&self, index: i32) -> Result<u64>
fn get_u64_idx_def(&self, index: i32) -> Result<u64>
source§impl Debug for CommandLineParser
impl Debug for CommandLineParser
source§impl Drop for CommandLineParser
impl Drop for CommandLineParser
impl Send for CommandLineParser
Auto Trait Implementations§
impl Freeze for CommandLineParser
impl RefUnwindSafe for CommandLineParser
impl !Sync for CommandLineParser
impl Unpin for CommandLineParser
impl UnwindSafe for CommandLineParser
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res ) -> Res
Mat
or another similar object. By passing
a mutable reference to the Mat
to this function your closure will get called with the read reference and a write references
to the same Mat
. This is of course unsafe as it breaks the Rust aliasing rules, but it might be useful for some performance
sensitive operations. One example of an OpenCV function that allows such in-place modification is imgproc::threshold
. Read more