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
423b721d
Commit
423b721d
authored
Apr 18, 2012
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed AlgorithmInfo::read for read only parameters (thanks to Vadim)
parent
78ee81c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
24 deletions
+39
-24
core.hpp
modules/core/include/opencv2/core/core.hpp
+3
-1
algorithm.cpp
modules/core/src/algorithm.cpp
+36
-23
No files found.
modules/core/include/opencv2/core/core.hpp
View file @
423b721d
...
@@ -4312,10 +4312,10 @@ public:
...
@@ -4312,10 +4312,10 @@ public:
class
CV_EXPORTS
AlgorithmInfo
class
CV_EXPORTS
AlgorithmInfo
{
{
public
:
public
:
friend
class
Algorithm
;
AlgorithmInfo
(
const
string
&
name
,
Algorithm
::
Constructor
create
);
AlgorithmInfo
(
const
string
&
name
,
Algorithm
::
Constructor
create
);
~
AlgorithmInfo
();
~
AlgorithmInfo
();
void
get
(
const
Algorithm
*
algo
,
const
char
*
name
,
int
argType
,
void
*
value
)
const
;
void
get
(
const
Algorithm
*
algo
,
const
char
*
name
,
int
argType
,
void
*
value
)
const
;
void
set
(
Algorithm
*
algo
,
const
char
*
name
,
int
argType
,
const
void
*
value
)
const
;
void
addParam_
(
Algorithm
&
algo
,
const
char
*
name
,
int
argType
,
void
addParam_
(
Algorithm
&
algo
,
const
char
*
name
,
int
argType
,
void
*
value
,
bool
readOnly
,
void
*
value
,
bool
readOnly
,
Algorithm
::
Getter
getter
,
Algorithm
::
Setter
setter
,
Algorithm
::
Getter
getter
,
Algorithm
::
Setter
setter
,
...
@@ -4365,6 +4365,8 @@ public:
...
@@ -4365,6 +4365,8 @@ public:
const
string
&
help
=
string
());
const
string
&
help
=
string
());
protected
:
protected
:
AlgorithmInfoData
*
data
;
AlgorithmInfoData
*
data
;
void
set
(
Algorithm
*
algo
,
const
char
*
name
,
int
argType
,
const
void
*
value
,
bool
force
=
false
)
const
;
};
};
...
...
modules/core/src/algorithm.cpp
View file @
423b721d
...
@@ -296,9 +296,9 @@ AlgorithmInfo::~AlgorithmInfo()
...
@@ -296,9 +296,9 @@ AlgorithmInfo::~AlgorithmInfo()
void
AlgorithmInfo
::
write
(
const
Algorithm
*
algo
,
FileStorage
&
fs
)
const
void
AlgorithmInfo
::
write
(
const
Algorithm
*
algo
,
FileStorage
&
fs
)
const
{
{
size_t
i
=
0
,
n
=
data
->
params
.
vec
.
size
();
size_t
i
=
0
,
n
params
=
data
->
params
.
vec
.
size
();
cv
::
write
(
fs
,
"name"
,
algo
->
name
());
cv
::
write
(
fs
,
"name"
,
algo
->
name
());
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
n
params
;
i
++
)
{
{
const
Param
&
p
=
data
->
params
.
vec
[
i
].
second
;
const
Param
&
p
=
data
->
params
.
vec
[
i
].
second
;
const
string
&
pname
=
data
->
params
.
vec
[
i
].
first
;
const
string
&
pname
=
data
->
params
.
vec
[
i
].
first
;
...
@@ -327,9 +327,10 @@ void AlgorithmInfo::write(const Algorithm* algo, FileStorage& fs) const
...
@@ -327,9 +327,10 @@ void AlgorithmInfo::write(const Algorithm* algo, FileStorage& fs) const
void
AlgorithmInfo
::
read
(
Algorithm
*
algo
,
const
FileNode
&
fn
)
const
void
AlgorithmInfo
::
read
(
Algorithm
*
algo
,
const
FileNode
&
fn
)
const
{
{
size_t
i
=
0
,
n
=
data
->
params
.
vec
.
size
();
size_t
i
=
0
,
nparams
=
data
->
params
.
vec
.
size
();
AlgorithmInfo
*
info
=
algo
->
info
();
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
n
params
;
i
++
)
{
{
const
Param
&
p
=
data
->
params
.
vec
[
i
].
second
;
const
Param
&
p
=
data
->
params
.
vec
[
i
].
second
;
const
string
&
pname
=
data
->
params
.
vec
[
i
].
first
;
const
string
&
pname
=
data
->
params
.
vec
[
i
].
first
;
...
@@ -337,31 +338,43 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
...
@@ -337,31 +338,43 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
if
(
n
.
empty
()
)
if
(
n
.
empty
()
)
continue
;
continue
;
if
(
p
.
type
==
Param
::
INT
)
if
(
p
.
type
==
Param
::
INT
)
algo
->
set
(
pname
,
(
int
)
n
);
{
int
val
=
(
int
)
n
;
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
val
,
true
);
}
else
if
(
p
.
type
==
Param
::
BOOLEAN
)
else
if
(
p
.
type
==
Param
::
BOOLEAN
)
algo
->
set
(
pname
,
(
int
)
n
!=
0
);
{
bool
val
=
(
int
)
n
!=
0
;
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
val
,
true
);
}
else
if
(
p
.
type
==
Param
::
REAL
)
else
if
(
p
.
type
==
Param
::
REAL
)
algo
->
set
(
pname
,
(
double
)
n
);
{
double
val
=
(
double
)
n
;
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
val
,
true
);
}
else
if
(
p
.
type
==
Param
::
STRING
)
else
if
(
p
.
type
==
Param
::
STRING
)
algo
->
set
(
pname
,
(
string
)
n
);
{
string
val
=
(
string
)
n
;
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
val
,
true
);
}
else
if
(
p
.
type
==
Param
::
MAT
)
else
if
(
p
.
type
==
Param
::
MAT
)
{
{
Mat
m
;
Mat
m
;
cv
::
read
(
n
,
m
);
cv
::
read
(
n
,
m
);
algo
->
set
(
pname
,
m
);
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
m
,
true
);
}
}
else
if
(
p
.
type
==
Param
::
MAT_VECTOR
)
else
if
(
p
.
type
==
Param
::
MAT_VECTOR
)
{
{
vector
<
Mat
>
mv
;
vector
<
Mat
>
mv
;
cv
::
read
(
n
,
mv
);
cv
::
read
(
n
,
mv
);
algo
->
set
(
pname
,
mv
);
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
mv
,
true
);
}
}
else
if
(
p
.
type
==
Param
::
ALGORITHM
)
else
if
(
p
.
type
==
Param
::
ALGORITHM
)
{
{
Ptr
<
Algorithm
>
nestedAlgo
=
Algorithm
::
_create
((
string
)
n
[
"name"
]);
Ptr
<
Algorithm
>
nestedAlgo
=
Algorithm
::
_create
((
string
)
n
[
"name"
]);
CV_Assert
(
!
nestedAlgo
.
empty
()
);
CV_Assert
(
!
nestedAlgo
.
empty
()
);
nestedAlgo
->
read
(
n
);
nestedAlgo
->
read
(
n
);
algo
->
set
(
pname
,
nestedAlgo
);
info
->
set
(
algo
,
pname
.
c_str
(),
p
.
type
,
&
nestedAlgo
,
true
);
}
}
else
else
CV_Error
(
CV_StsUnsupportedFormat
,
"unknown/unsupported parameter type"
);
CV_Error
(
CV_StsUnsupportedFormat
,
"unknown/unsupported parameter type"
);
...
@@ -391,24 +404,24 @@ union GetSetParam
...
@@ -391,24 +404,24 @@ union GetSetParam
void
(
Algorithm
::*
set_mat_vector
)(
const
vector
<
Mat
>&
);
void
(
Algorithm
::*
set_mat_vector
)(
const
vector
<
Mat
>&
);
void
(
Algorithm
::*
set_algo
)(
const
Ptr
<
Algorithm
>&
);
void
(
Algorithm
::*
set_algo
)(
const
Ptr
<
Algorithm
>&
);
};
};
void
AlgorithmInfo
::
set
(
Algorithm
*
algo
,
const
char
*
name
,
int
argType
,
const
void
*
value
)
const
void
AlgorithmInfo
::
set
(
Algorithm
*
algo
,
const
char
*
name
,
int
argType
,
const
void
*
value
,
bool
force
)
const
{
{
const
Param
*
p
=
findstr
(
data
->
params
,
name
);
const
Param
*
p
=
findstr
(
data
->
params
,
name
);
if
(
!
p
)
if
(
!
p
)
CV_Error_
(
CV_StsBadArg
,
(
"No parameter '%s' is found"
,
name
?
name
:
"<NULL>"
)
);
CV_Error_
(
CV_StsBadArg
,
(
"No parameter '%s' is found"
,
name
?
name
:
"<NULL>"
)
);
if
(
p
->
readonly
)
if
(
!
force
&&
p
->
readonly
)
CV_Error_
(
CV_StsError
,
(
"Parameter '%s' is readonly"
,
name
));
CV_Error_
(
CV_StsError
,
(
"Parameter '%s' is readonly"
,
name
));
GetSetParam
f
;
GetSetParam
f
;
f
.
set_int
=
p
->
setter
;
f
.
set_int
=
p
->
setter
;
if
(
argType
==
Param
::
INT
||
argType
==
Param
::
BOOLEAN
||
argType
==
Param
::
REAL
)
if
(
argType
==
Param
::
INT
||
argType
==
Param
::
BOOLEAN
||
argType
==
Param
::
REAL
)
{
{
CV_Assert
(
p
->
type
==
Param
::
INT
||
p
->
type
==
Param
::
REAL
||
p
->
type
==
Param
::
BOOLEAN
);
CV_Assert
(
p
->
type
==
Param
::
INT
||
p
->
type
==
Param
::
REAL
||
p
->
type
==
Param
::
BOOLEAN
);
if
(
p
->
type
==
Param
::
INT
)
if
(
p
->
type
==
Param
::
INT
)
{
{
int
val
=
argType
==
Param
::
INT
?
*
(
const
int
*
)
value
:
int
val
=
argType
==
Param
::
INT
?
*
(
const
int
*
)
value
:
...
@@ -443,7 +456,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
...
@@ -443,7 +456,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
else
if
(
argType
==
Param
::
STRING
)
else
if
(
argType
==
Param
::
STRING
)
{
{
CV_Assert
(
p
->
type
==
Param
::
STRING
);
CV_Assert
(
p
->
type
==
Param
::
STRING
);
const
string
&
val
=
*
(
const
string
*
)
value
;
const
string
&
val
=
*
(
const
string
*
)
value
;
if
(
p
->
setter
)
if
(
p
->
setter
)
(
algo
->*
f
.
set_string
)(
val
);
(
algo
->*
f
.
set_string
)(
val
);
...
@@ -453,7 +466,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
...
@@ -453,7 +466,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
else
if
(
argType
==
Param
::
MAT
)
else
if
(
argType
==
Param
::
MAT
)
{
{
CV_Assert
(
p
->
type
==
Param
::
MAT
);
CV_Assert
(
p
->
type
==
Param
::
MAT
);
const
Mat
&
val
=
*
(
const
Mat
*
)
value
;
const
Mat
&
val
=
*
(
const
Mat
*
)
value
;
if
(
p
->
setter
)
if
(
p
->
setter
)
(
algo
->*
f
.
set_mat
)(
val
);
(
algo
->*
f
.
set_mat
)(
val
);
...
@@ -463,7 +476,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
...
@@ -463,7 +476,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
else
if
(
argType
==
Param
::
MAT_VECTOR
)
else
if
(
argType
==
Param
::
MAT_VECTOR
)
{
{
CV_Assert
(
p
->
type
==
Param
::
MAT_VECTOR
);
CV_Assert
(
p
->
type
==
Param
::
MAT_VECTOR
);
const
vector
<
Mat
>&
val
=
*
(
const
vector
<
Mat
>*
)
value
;
const
vector
<
Mat
>&
val
=
*
(
const
vector
<
Mat
>*
)
value
;
if
(
p
->
setter
)
if
(
p
->
setter
)
(
algo
->*
f
.
set_mat_vector
)(
val
);
(
algo
->*
f
.
set_mat_vector
)(
val
);
...
@@ -473,7 +486,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
...
@@ -473,7 +486,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
else
if
(
argType
==
Param
::
ALGORITHM
)
else
if
(
argType
==
Param
::
ALGORITHM
)
{
{
CV_Assert
(
p
->
type
==
Param
::
ALGORITHM
);
CV_Assert
(
p
->
type
==
Param
::
ALGORITHM
);
const
Ptr
<
Algorithm
>&
val
=
*
(
const
Ptr
<
Algorithm
>*
)
value
;
const
Ptr
<
Algorithm
>&
val
=
*
(
const
Ptr
<
Algorithm
>*
)
value
;
if
(
p
->
setter
)
if
(
p
->
setter
)
(
algo
->*
f
.
set_algo
)(
val
);
(
algo
->*
f
.
set_algo
)(
val
);
...
...
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