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
f87de190
Commit
f87de190
authored
Nov 23, 2010
by
Gary Bradski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more documenation
parent
89c4bc54
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
filestorage_sample.cpp
samples/cpp/filestorage_sample.cpp
+11
-6
No files found.
samples/cpp/filestorage_sample.cpp
View file @
f87de190
...
...
@@ -15,9 +15,13 @@ using namespace cv;
void
help
(
char
**
av
)
{
cout
<<
"usage:
\n
"
<<
av
[
0
]
<<
" outputfile.yml.gz
\n
"
<<
"Try using different extensions.(e.g. yaml yml xml xml.gz etc...)
\n
"
<<
"This will serialize some matrices and image names to the format specified."
<<
endl
;
cout
<<
"usage:
\n
"
<<
av
[
0
]
<<
" outputfile.yml.gz
\n
"
<<
"
\n
outputfile above can have many different extenstions, see below."
<<
"
\n
This program demonstrates the use of FileStorage for serialization, that is use << and >> in OpenCV
\n
"
<<
"For example, how to create a class and have it serialize, but also how to use it to read and write matrices.
\n
"
<<
"FileStorage allows you to serialize to various formats specified by the file end type."
<<
"
\n
You should try using different file extensions.(e.g. yaml yml xml xml.gz yaml.gz etc...)
\n
"
<<
endl
;
}
struct
MyData
...
...
@@ -33,11 +37,11 @@ struct MyData
int
A
;
double
X
;
string
id
;
void
write
(
FileStorage
&
fs
)
const
void
write
(
FileStorage
&
fs
)
const
//Write serialization for this class
{
fs
<<
"{"
<<
"A"
<<
A
<<
"X"
<<
X
<<
"id"
<<
id
<<
"}"
;
}
void
read
(
const
FileNode
&
node
)
void
read
(
const
FileNode
&
node
)
//Read serialization for this class
{
A
=
(
int
)
node
[
"A"
];
...
...
@@ -46,6 +50,7 @@ struct MyData
}
};
//These write and read functions must exist as per the inline functions in operations.hpp
void
write
(
FileStorage
&
fs
,
const
std
::
string
&
name
,
const
MyData
&
x
){
x
.
write
(
fs
);
}
...
...
@@ -137,7 +142,7 @@ int main(int ac, char** av)
cout
<<
"read mdata
\n
"
;
cout
<<
m
<<
endl
;
cout
<<
"attempting to read mdata_b
\n
"
;
cout
<<
"attempting to read mdata_b
\n
"
;
//Show default behavior for empty matrix
fs
[
"mdata_b"
]
>>
m
;
cout
<<
"read mdata_b
\n
"
;
cout
<<
m
<<
endl
;
...
...
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