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
6cf9070b
Commit
6cf9070b
authored
Aug 14, 2013
by
Bahram Dahi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to read several opencv types (Size, Point, etc.) to FileStorage. Solves issue #3196
parent
43c7a8ae
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
1 deletion
+87
-1
operations.hpp
modules/core/include/opencv2/core/operations.hpp
+52
-0
test_io.cpp
modules/core/test/test_io.cpp
+35
-1
No files found.
modules/core/include/opencv2/core/operations.hpp
View file @
6cf9070b
...
...
@@ -3001,6 +3001,58 @@ static inline void read(const FileNode& node, string& value, const string& defau
value
=
!
node
.
node
?
default_value
:
CV_NODE_IS_STRING
(
node
.
node
->
tag
)
?
string
(
node
.
node
->
data
.
str
.
ptr
)
:
string
(
""
);
}
template
<
typename
_Tp
>
static
inline
void
read
(
const
FileNode
&
node
,
Point_
<
_Tp
>&
value
,
const
Point_
<
_Tp
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
2
?
default_value
:
Point_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
temp
[
0
]),
saturate_cast
<
_Tp
>
(
temp
[
1
]));
}
template
<
typename
_Tp
>
static
inline
void
read
(
const
FileNode
&
node
,
Point3_
<
_Tp
>&
value
,
const
Point3_
<
_Tp
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
3
?
default_value
:
Point3_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
temp
[
0
]),
saturate_cast
<
_Tp
>
(
temp
[
1
]),
saturate_cast
<
_Tp
>
(
temp
[
2
]));
}
template
<
typename
_Tp
>
static
inline
void
read
(
const
FileNode
&
node
,
Size_
<
_Tp
>&
value
,
const
Size_
<
_Tp
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
2
?
default_value
:
Size_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
temp
[
0
]),
saturate_cast
<
_Tp
>
(
temp
[
1
]));
}
template
<
typename
_Tp
>
static
inline
void
read
(
const
FileNode
&
node
,
Complex
<
_Tp
>&
value
,
const
Complex
<
_Tp
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
2
?
default_value
:
Complex
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
temp
[
0
]),
saturate_cast
<
_Tp
>
(
temp
[
1
]));
}
template
<
typename
_Tp
>
static
inline
void
read
(
const
FileNode
&
node
,
Rect_
<
_Tp
>&
value
,
Rect_
<
_Tp
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
4
?
default_value
:
Rect_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
temp
[
0
]),
saturate_cast
<
_Tp
>
(
temp
[
1
]),
saturate_cast
<
_Tp
>
(
temp
[
2
]),
saturate_cast
<
_Tp
>
(
temp
[
3
]));
}
template
<
typename
_Tp
,
int
cn
>
static
inline
void
read
(
const
FileNode
&
node
,
Vec
<
_Tp
,
cn
>&
value
,
const
Vec
<
_Tp
,
cn
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
cn
?
default_value
:
Vec
<
_Tp
,
cn
>
(
&
temp
[
0
]);
}
template
<
typename
_Tp
>
static
inline
void
read
(
const
FileNode
&
node
,
Scalar_
<
_Tp
>&
value
,
const
Scalar_
<
_Tp
>&
default_value
)
{
vector
<
_Tp
>
temp
;
FileNodeIterator
it
=
node
.
begin
();
it
>>
temp
;
value
=
temp
.
size
()
!=
4
?
default_value
:
Scalar_
<
_Tp
>
(
saturate_cast
<
_Tp
>
(
temp
[
0
]),
saturate_cast
<
_Tp
>
(
temp
[
1
]),
saturate_cast
<
_Tp
>
(
temp
[
2
]),
saturate_cast
<
_Tp
>
(
temp
[
3
]));
}
static
inline
void
read
(
const
FileNode
&
node
,
Range
&
value
,
const
Range
&
default_value
)
{
Point2i
temp
(
value
.
start
,
value
.
end
);
const
Point2i
default_temp
=
Point2i
(
default_value
.
start
,
default_value
.
end
);
read
(
node
,
temp
,
default_temp
);
value
.
start
=
temp
.
x
;
value
.
end
=
temp
.
y
;
}
CV_EXPORTS_W
void
read
(
const
FileNode
&
node
,
Mat
&
mat
,
const
Mat
&
default_mat
=
Mat
()
);
CV_EXPORTS
void
read
(
const
FileNode
&
node
,
SparseMat
&
mat
,
const
SparseMat
&
default_mat
=
SparseMat
()
);
...
...
modules/core/test/test_io.cpp
View file @
6cf9070b
...
...
@@ -390,7 +390,6 @@ protected:
try
{
string
fname
=
cv
::
tempfile
(
".xml"
);
FileStorage
fs
(
fname
,
FileStorage
::
WRITE
);
vector
<
int
>
mi
,
mi2
,
mi3
,
mi4
;
vector
<
Mat
>
mv
,
mv2
,
mv3
,
mv4
;
Mat
m
(
10
,
9
,
CV_32F
);
...
...
@@ -398,24 +397,59 @@ protected:
randu
(
m
,
0
,
1
);
mi3
.
push_back
(
5
);
mv3
.
push_back
(
m
);
Point_
<
float
>
p1
(
1.1
f
,
2.2
f
),
op1
;
Point3i
p2
(
3
,
4
,
5
),
op2
;
Size
s1
(
6
,
7
),
os1
;
Complex
<
int
>
c1
(
9
,
10
),
oc1
;
Rect
r1
(
11
,
12
,
13
,
14
),
or1
;
Vec
<
int
,
5
>
v1
(
15
,
16
,
17
,
18
,
19
),
ov1
;
Scalar
sc1
(
20.0
,
21.1
,
22.2
,
23.3
),
osc1
;
Range
g1
(
7
,
8
),
og1
;
FileStorage
fs
(
fname
,
FileStorage
::
WRITE
);
fs
<<
"mi"
<<
mi
;
fs
<<
"mv"
<<
mv
;
fs
<<
"mi3"
<<
mi3
;
fs
<<
"mv3"
<<
mv3
;
fs
<<
"empty"
<<
empty
;
fs
<<
"p1"
<<
p1
;
fs
<<
"p2"
<<
p2
;
fs
<<
"s1"
<<
s1
;
fs
<<
"c1"
<<
c1
;
fs
<<
"r1"
<<
r1
;
fs
<<
"v1"
<<
v1
;
fs
<<
"sc1"
<<
sc1
;
fs
<<
"g1"
<<
g1
;
fs
.
release
();
fs
.
open
(
fname
,
FileStorage
::
READ
);
fs
[
"mi"
]
>>
mi2
;
fs
[
"mv"
]
>>
mv2
;
fs
[
"mi3"
]
>>
mi4
;
fs
[
"mv3"
]
>>
mv4
;
fs
[
"empty"
]
>>
empty
;
fs
[
"p1"
]
>>
op1
;
fs
[
"p2"
]
>>
op2
;
fs
[
"s1"
]
>>
os1
;
fs
[
"c1"
]
>>
oc1
;
fs
[
"r1"
]
>>
or1
;
fs
[
"v1"
]
>>
ov1
;
fs
[
"sc1"
]
>>
osc1
;
fs
[
"g1"
]
>>
og1
;
CV_Assert
(
mi2
.
empty
()
);
CV_Assert
(
mv2
.
empty
()
);
CV_Assert
(
norm
(
mi3
,
mi4
,
CV_C
)
==
0
);
CV_Assert
(
mv4
.
size
()
==
1
);
double
n
=
norm
(
mv3
[
0
],
mv4
[
0
],
CV_C
);
CV_Assert
(
n
==
0
);
CV_Assert
(
op1
==
p1
);
CV_Assert
(
op2
==
p2
);
CV_Assert
(
os1
==
s1
);
CV_Assert
(
oc1
==
c1
);
CV_Assert
(
or1
==
r1
);
CV_Assert
(
ov1
==
v1
);
CV_Assert
(
osc1
==
sc1
);
CV_Assert
(
og1
==
g1
);
}
catch
(...)
{
...
...
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