Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
05b16367
Commit
05b16367
authored
Sep 21, 2015
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5329 from paroj:cliparser
parents
00512086
31da8335
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
18 deletions
+32
-18
utility.hpp
modules/core/include/opencv2/core/utility.hpp
+5
-1
command_line_parser.cpp
modules/core/src/command_line_parser.cpp
+19
-9
ts_perf.cpp
modules/ts/src/ts_perf.cpp
+8
-8
No files found.
modules/core/include/opencv2/core/utility.hpp
View file @
05b16367
...
...
@@ -619,6 +619,10 @@ For example:
}
@endcode
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.
### Usage
For the described keys:
...
...
@@ -630,7 +634,7 @@ For the described keys:
# Bad call
$ ./app -fps=aaa
ERRORS:
Exception
: can not convert: [aaa] to [double]
Parameter 'fps'
: can not convert: [aaa] to [double]
@endcode
*/
class
CV_EXPORTS
CommandLineParser
...
...
modules/core/src/command_line_parser.cpp
View file @
05b16367
...
...
@@ -97,23 +97,28 @@ void CommandLineParser::getByName(const String& name, bool space_delete, int typ
{
for
(
size_t
j
=
0
;
j
<
impl
->
data
[
i
].
keys
.
size
();
j
++
)
{
if
(
name
.
compare
(
impl
->
data
[
i
].
keys
[
j
])
==
0
)
if
(
name
==
impl
->
data
[
i
].
keys
[
j
]
)
{
String
v
=
impl
->
data
[
i
].
def_value
;
if
(
space_delete
)
v
=
impl
->
cat_string
(
v
);
// it is an error if we just got the default value here
if
(
v
.
empty
())
break
;
from_str
(
v
,
type
,
dst
);
return
;
}
}
}
impl
->
error
=
true
;
impl
->
error_message
=
impl
->
error_message
+
"
Unknown parameter "
+
name
+
"
\n
"
;
impl
->
error_message
=
impl
->
error_message
+
"
Missing parameter: '"
+
name
+
"'
\n
"
;
}
catch
(
std
::
e
xception
&
e
)
catch
(
E
xception
&
e
)
{
impl
->
error
=
true
;
impl
->
error_message
=
impl
->
error_message
+
"
Exception: "
+
String
(
e
.
what
())
+
"
\n
"
;
impl
->
error_message
=
impl
->
error_message
+
"
Parameter '"
+
name
+
"': "
+
e
.
err
+
"
\n
"
;
}
}
...
...
@@ -128,17 +133,22 @@ void CommandLineParser::getByIndex(int index, bool space_delete, int type, void*
{
String
v
=
impl
->
data
[
i
].
def_value
;
if
(
space_delete
==
true
)
v
=
impl
->
cat_string
(
v
);
// it is an error if we just got the default value here
if
(
v
.
empty
())
break
;
from_str
(
v
,
type
,
dst
);
return
;
}
}
impl
->
error
=
true
;
impl
->
error_message
=
impl
->
error_message
+
"
Unknown
parameter #"
+
format
(
"%d"
,
index
)
+
"
\n
"
;
impl
->
error_message
=
impl
->
error_message
+
"
Missing
parameter #"
+
format
(
"%d"
,
index
)
+
"
\n
"
;
}
catch
(
std
::
exception
&
e
)
catch
(
Exception
&
e
)
{
impl
->
error
=
true
;
impl
->
error_message
=
impl
->
error_message
+
"Exception: "
+
String
(
e
.
what
())
+
"
\n
"
;
impl
->
error_message
=
impl
->
error_message
+
format
(
"Parameter #%d: "
,
index
)
+
e
.
err
+
"
\n
"
;
}
}
...
...
@@ -324,9 +334,9 @@ bool CommandLineParser::has(const String& name) const
{
for
(
size_t
j
=
0
;
j
<
impl
->
data
[
i
].
keys
.
size
();
j
++
)
{
if
(
name
.
compare
(
impl
->
data
[
i
].
keys
[
j
])
==
0
&&
String
(
"true"
).
compare
(
impl
->
data
[
i
].
def_value
)
==
0
)
if
(
name
==
impl
->
data
[
i
].
keys
[
j
]
)
{
return
true
;
return
!
impl
->
cat_string
(
impl
->
data
[
i
].
def_value
).
empty
()
;
}
}
}
...
...
modules/ts/src/ts_perf.cpp
View file @
05b16367
...
...
@@ -783,7 +783,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
;
cv
::
CommandLineParser
args
(
argc
,
argv
,
command_line_keys
);
if
(
args
.
has
(
"help"
))
if
(
args
.
get
<
bool
>
(
"help"
))
{
args
.
printMessage
();
return
;
...
...
@@ -791,7 +791,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
::
testing
::
AddGlobalTestEnvironment
(
new
PerfEnvironment
);
param_impl
=
args
.
has
(
"perf_run_cpu"
)
?
"plain"
:
args
.
get
<
std
::
string
>
(
"perf_impl"
);
param_impl
=
args
.
get
<
bool
>
(
"perf_run_cpu"
)
?
"plain"
:
args
.
get
<
std
::
string
>
(
"perf_impl"
);
std
::
string
perf_strategy
=
args
.
get
<
std
::
string
>
(
"perf_strategy"
);
if
(
perf_strategy
==
"default"
)
{
...
...
@@ -816,24 +816,24 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
param_seed
=
args
.
get
<
unsigned
int
>
(
"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
.
has
(
"perf_write_sanity"
);
param_verify_sanity
=
args
.
has
(
"perf_verify_sanity"
);
param_write_sanity
=
args
.
get
<
bool
>
(
"perf_write_sanity"
);
param_verify_sanity
=
args
.
get
<
bool
>
(
"perf_verify_sanity"
);
#ifndef WINRT
test_ipp_check
=
!
args
.
has
(
"perf_ipp_check"
)
?
getenv
(
"OPENCV_IPP_CHECK"
)
!=
NULL
:
true
;
test_ipp_check
=
!
args
.
get
<
bool
>
(
"perf_ipp_check"
)
?
getenv
(
"OPENCV_IPP_CHECK"
)
!=
NULL
:
true
;
#else
test_ipp_check
=
false
;
#endif
param_threads
=
args
.
get
<
int
>
(
"perf_threads"
);
#ifdef CV_COLLECT_IMPL_DATA
param_collect_impl
=
args
.
has
(
"perf_collect_impl"
);
param_collect_impl
=
args
.
get
<
bool
>
(
"perf_collect_impl"
);
#endif
#ifdef ANDROID
param_affinity_mask
=
args
.
get
<
int
>
(
"perf_affinity_mask"
);
log_power_checkpoints
=
args
.
has
(
"perf_log_power_checkpoints"
);
#endif
bool
param_list_impls
=
args
.
has
(
"perf_list_impls"
);
bool
param_list_impls
=
args
.
get
<
bool
>
(
"perf_list_impls"
);
if
(
param_list_impls
)
{
...
...
@@ -861,7 +861,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
#ifdef HAVE_CUDA
bool
printOnly
=
args
.
has
(
"perf_cuda_info_only"
);
bool
printOnly
=
args
.
get
<
bool
>
(
"perf_cuda_info_only"
);
if
(
printOnly
)
exit
(
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment