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
0598f33a
Commit
0598f33a
authored
Sep 07, 2012
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored command line parser, fixed the docs
parent
b16b50d6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
116 deletions
+47
-116
command_line_parser.rst
modules/core/doc/command_line_parser.rst
+5
-5
core.hpp
modules/core/include/opencv2/core/core.hpp
+42
-111
command_line_parser.cpp
modules/core/src/command_line_parser.cpp
+0
-0
No files found.
modules/core/doc/command_line_parser.rst
View file @
0598f33a
...
@@ -58,15 +58,15 @@ The sample below demonstrates how to use CommandLineParser:
...
@@ -58,15 +58,15 @@ The sample below demonstrates how to use CommandLineParser:
}
}
int N = parser.get<int>("N");
int N = parser.get<int>("N");
double fps = parser.get<double>
parser
("fps");
double fps = parser.get<double>("fps");
std::string path = parser.get<std::string>("path");
std::string path = parser.get<std::string>("path");
use_time_stamp = parser
er
.has("timestamp");
use_time_stamp = parser.has("timestamp");
std::string img1 = parser.get<string>(
1
);
std::string img1 = parser.get<string>(
0
);
std::string img2 = parser.get<string>(
2
);
std::string img2 = parser.get<string>(
1
);
int repeat = parser.get<int>(
3
);
int repeat = parser.get<int>(
2
);
if (!parser.check())
if (!parser.check())
{
{
...
...
modules/core/include/opencv2/core/core.hpp
View file @
0598f33a
...
@@ -221,7 +221,7 @@ CV_EXPORTS void setNumThreads(int nthreads);
...
@@ -221,7 +221,7 @@ CV_EXPORTS void setNumThreads(int nthreads);
CV_EXPORTS
int
getNumThreads
();
CV_EXPORTS
int
getNumThreads
();
CV_EXPORTS
int
getThreadNum
();
CV_EXPORTS
int
getThreadNum
();
CV_EXPORTS_W
const
st
d
::
st
ring
&
getBuildInformation
();
CV_EXPORTS_W
const
string
&
getBuildInformation
();
//! Returns the number of ticks.
//! Returns the number of ticks.
...
@@ -4434,7 +4434,7 @@ protected:
...
@@ -4434,7 +4434,7 @@ protected:
struct
CV_EXPORTS
Param
struct
CV_EXPORTS
Param
{
{
enum
{
INT
=
0
,
BOOLEAN
=
1
,
REAL
=
2
,
STRING
=
3
,
MAT
=
4
,
MAT_VECTOR
=
5
,
ALGORITHM
=
6
};
enum
{
INT
=
0
,
BOOLEAN
=
1
,
REAL
=
2
,
STRING
=
3
,
MAT
=
4
,
MAT_VECTOR
=
5
,
ALGORITHM
=
6
,
FLOAT
=
7
,
UNSIGNED_INT
=
8
,
UINT64
=
9
};
Param
();
Param
();
Param
(
int
_type
,
bool
_readonly
,
int
_offset
,
Param
(
int
_type
,
bool
_readonly
,
int
_offset
,
...
@@ -4505,142 +4505,73 @@ template<> struct ParamType<Algorithm>
...
@@ -4505,142 +4505,73 @@ template<> struct ParamType<Algorithm>
enum
{
type
=
Param
::
ALGORITHM
};
enum
{
type
=
Param
::
ALGORITHM
};
};
};
// The CommandLineParser class is designed for command line arguments parsing
template
<>
struct
ParamType
<
float
>
class
CV_EXPORTS
CommandLineParserParams
{
{
public
:
typedef
float
const_param_type
;
std
::
string
help_message
;
typedef
float
member_type
;
std
::
string
def_value
;
std
::
vector
<
std
::
string
>
keys
;
enum
{
type
=
Param
::
FLOAT
};
int
number
;
};
};
template
<
typename
T
>
template
<>
struct
ParamType
<
unsigned
>
std
::
string
get_type_name
()
{
return
"UNKNOW"
;
}
{
typedef
unsigned
const_param_type
;
typedef
unsigned
member_type
;
bool
cmp_params
(
const
CommandLineParserParams
&
p1
,
const
CommandLineParserParams
&
p2
);
enum
{
type
=
Param
::
UNSIGNED_INT
};
};
template
<
typename
T
>
template
<>
struct
ParamType
<
uint64
>
T
from_str
(
const
std
::
string
&
str
)
{
{
T
value
;
typedef
uint64
const_param_type
;
std
::
stringstream
ss
(
str
);
typedef
uint64
member_type
;
ss
>>
value
;
if
(
ss
.
fail
())
enum
{
type
=
Param
::
UINT64
};
{
};
std
::
string
err_msg
=
std
::
string
(
"can not convert: ["
)
+
str
+
std
::
string
(
"] to ["
)
+
get_type_name
<
T
>
()
+
std
::
string
(
"]"
);
CV_Error
(
CV_StsBadArg
,
err_msg
);
}
return
value
;
}
template
<>
std
::
string
from_str
(
const
std
::
string
&
str
);
template
<
typename
T
>
// The CommandLineParser class is designed for command line arguments parsing
std
::
string
to_str
(
T
value
)
{
std
::
ostringstream
os
;
os
<<
value
;
return
os
.
str
();
}
class
CV_EXPORTS
CommandLineParser
class
CV_EXPORTS
CommandLineParser
{
{
public
:
public
:
CommandLineParser
(
int
argc
,
const
char
*
const
argv
[],
const
std
::
string
keys
);
CommandLineParser
(
int
argc
,
const
char
*
const
argv
[],
const
string
&
keys
);
CommandLineParser
(
const
CommandLineParser
&
parser
);
CommandLineParser
&
operator
=
(
const
CommandLineParser
&
parser
);
std
::
string
getPathToApplication
()
;
string
getPathToApplication
()
const
;
template
<
typename
T
>
template
<
typename
T
>
T
get
(
const
std
::
string
&
name
,
bool
space_delete
=
true
)
T
get
(
const
string
&
name
,
bool
space_delete
=
true
)
const
{
try
{
for
(
size_t
i
=
0
;
i
<
data
.
size
();
i
++
)
{
{
for
(
size_t
j
=
0
;
j
<
data
[
i
].
keys
.
size
();
j
++
)
T
val
=
T
();
{
getByName
(
name
,
space_delete
,
ParamType
<
T
>::
type
,
(
void
*
)
&
val
);
if
(
name
.
compare
(
data
[
i
].
keys
[
j
])
==
0
)
return
val
;
{
std
::
string
v
=
data
[
i
].
def_value
;
if
(
space_delete
==
true
)
v
=
cat_string
(
v
);
return
from_str
<
T
>
(
v
);
}
}
}
error
=
true
;
error_message
+=
"Unknown parametes "
+
name
+
"
\n
"
;
}
catch
(
std
::
exception
&
e
)
{
error
=
true
;
error_message
+=
"Exception: "
+
std
::
string
(
e
.
what
())
+
"
\n
"
;
}
return
T
();
}
}
template
<
typename
T
>
template
<
typename
T
>
T
get
(
int
index
,
bool
space_delete
=
true
)
T
get
(
int
index
,
bool
space_delete
=
true
)
const
{
try
{
for
(
size_t
i
=
0
;
i
<
data
.
size
();
i
++
)
{
if
(
data
[
i
].
number
==
index
-
1
)
{
std
::
string
v
=
data
[
i
].
def_value
;
if
(
space_delete
==
true
)
v
=
cat_string
(
v
);
return
from_str
<
T
>
(
v
);
}
}
error
=
true
;
error_message
+=
"Unknown parametes #"
+
to_str
<
int
>
(
index
)
+
"
\n
"
;
}
catch
(
std
::
exception
&
e
)
{
{
error
=
true
;
T
val
=
T
();
error_message
+=
"Exception: "
+
std
::
string
(
e
.
what
())
+
"
\n
"
;
getByIndex
(
index
,
space_delete
,
ParamType
<
T
>::
type
,
(
void
*
)
&
val
);
return
val
;
}
}
return
T
();
}
bool
has
(
const
std
::
string
&
name
);
bool
check
();
void
about
(
std
::
string
message
);
void
printMessage
();
void
printErrors
();
protected
:
bool
has
(
const
string
&
name
)
const
;
bool
error
;
std
::
string
error_message
;
std
::
string
about_message
;
std
::
string
path_to_app
;
std
::
string
app_name
;
std
::
vector
<
CommandLineParserParams
>
data
;
bool
check
()
const
;
std
::
vector
<
std
::
string
>
split_range_string
(
std
::
string
str
,
char
fs
,
char
ss
);
void
about
(
const
string
&
message
);
std
::
vector
<
std
::
string
>
split_string
(
std
::
string
str
,
char
symbol
=
' '
,
bool
create_empty_item
=
false
);
std
::
string
cat_string
(
std
::
string
str
);
void
apply_params
(
std
::
string
key
,
std
::
string
value
)
;
void
printMessage
()
const
;
void
apply_params
(
int
i
,
std
::
string
value
)
;
void
printErrors
()
const
;
void
sort_params
();
protected
:
void
getByName
(
const
string
&
name
,
bool
space_delete
,
int
type
,
void
*
dst
)
const
;
void
getByIndex
(
int
index
,
bool
space_delete
,
int
type
,
void
*
dst
)
const
;
struct
Impl
;
Impl
*
impl
;
};
};
/////////////////////////////// Parallel Primitives //////////////////////////////////
/////////////////////////////// Parallel Primitives //////////////////////////////////
...
...
modules/core/src/command_line_parser.cpp
View file @
0598f33a
This diff is collapsed.
Click to expand it.
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