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
2e913625
Commit
2e913625
authored
Nov 20, 2010
by
Ethan Rublee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding two samples that deal with FileStorage - useful for creating image lists
parent
680dc71b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
191 additions
and
0 deletions
+191
-0
calibration.cpp
samples/cpp/calibration.cpp
+3
-0
filestorage_sample.cpp
samples/cpp/filestorage_sample.cpp
+150
-0
imagelist_creator.cpp
samples/cpp/imagelist_creator.cpp
+38
-0
No files found.
samples/cpp/calibration.cpp
View file @
2e913625
...
...
@@ -14,8 +14,10 @@ using namespace std;
calibration -w 4 -h 5 -s 0.025 -o camera.yml -op -oe
example command line for calibration from a list of stored images:
imagelist_creator image_list.xml *.png
calibration -w 4 -h 5 -s 0.025 -o camera.yml -op -oe image_list.xml
where image_list.xml is the standard OpenCV XML/YAML
use imagelist_creator to create the xml or yaml list
file consisting of the list of strings, e.g.:
<?xml version="1.0"?>
...
...
@@ -273,6 +275,7 @@ int main( int argc, char** argv )
" [-su] # show undistorted images after calibration
\n
"
" [input_data] # input data, one of the following:
\n
"
" # - text file with a list of the images of the board
\n
"
" # the text file can be generated with imagelist_creator
\n
"
" # - name of video file with a video of the board
\n
"
" # if input_data not specified, a live view from the camera is used
\n
"
"
\n
"
);
...
...
samples/cpp/filestorage_sample.cpp
0 → 100644
View file @
2e913625
/*
* filestorage_sample demonstrate the usage of the opencv serialization functionality
*/
#include "opencv2/core/core.hpp"
#include <iostream>
#include <string>
using
std
::
string
;
using
std
::
cout
;
using
std
::
endl
;
using
std
::
cerr
;
using
std
::
ostream
;
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
;
}
struct
MyData
{
MyData
()
:
A
(
0
),
X
(
0
),
id
()
{
}
explicit
MyData
(
int
)
:
A
(
97
),
X
(
CV_PI
),
id
(
"mydata1234"
)
{
}
int
A
;
double
X
;
string
id
;
void
write
(
FileStorage
&
fs
)
const
{
fs
<<
"{"
<<
"A"
<<
A
<<
"X"
<<
X
<<
"id"
<<
id
<<
"}"
;
}
void
read
(
const
FileNode
&
node
)
{
A
=
(
int
)
node
[
"A"
];
X
=
(
double
)
node
[
"X"
];
id
=
(
string
)
node
[
"id"
];
}
};
void
write
(
FileStorage
&
fs
,
const
std
::
string
&
name
,
const
MyData
&
x
){
x
.
write
(
fs
);
}
void
read
(
const
FileNode
&
node
,
MyData
&
x
,
const
MyData
&
default_value
=
MyData
()){
if
(
node
.
empty
())
x
=
default_value
;
else
x
=
(
MyData
)
node
;
}
ostream
&
operator
<<
(
ostream
&
out
,
const
MyData
&
m
){
out
<<
"{ id = "
<<
m
.
id
<<
", "
;
out
<<
"X = "
<<
m
.
X
<<
", "
;
out
<<
"A = "
<<
m
.
A
<<
"}"
;
return
out
;
}
int
main
(
int
ac
,
char
**
av
)
{
if
(
ac
!=
2
)
{
help
(
av
);
return
1
;
}
string
filename
=
av
[
1
];
//write
{
FileStorage
fs
(
filename
,
FileStorage
::
WRITE
);
cout
<<
"writing images
\n
"
;
fs
<<
"images"
<<
"["
;
fs
<<
"image1.jpg"
<<
"myfi.png"
<<
"baboon.jpg"
;
cout
<<
"image1.jpg"
<<
" myfi.png"
<<
" baboon.jpg"
<<
endl
;
fs
<<
"]"
;
cout
<<
"writing mats
\n
"
;
Mat
R
=
Mat_
<
double
>::
eye
(
3
,
3
),
T
=
Mat_
<
double
>::
zeros
(
3
,
1
);
cout
<<
"R = "
<<
R
<<
"
\n
"
;
cout
<<
"T = "
<<
T
<<
"
\n
"
;
fs
<<
"R"
<<
R
;
fs
<<
"T"
<<
T
;
cout
<<
"writing MyData struct
\n
"
;
MyData
m
(
1
);
fs
<<
"mdata"
<<
m
;
cout
<<
m
<<
endl
;
}
//read
{
FileStorage
fs
(
filename
,
FileStorage
::
READ
);
if
(
!
fs
.
isOpened
())
{
cerr
<<
"failed to open "
<<
filename
<<
endl
;
help
(
av
);
return
1
;
}
FileNode
n
=
fs
[
"images"
];
if
(
n
.
type
()
!=
FileNode
::
SEQ
)
{
cerr
<<
"images is not a sequence! FAIL"
<<
endl
;
return
1
;
}
cout
<<
"reading images
\n
"
;
FileNodeIterator
it
=
n
.
begin
(),
it_end
=
n
.
end
();
for
(;
it
!=
it_end
;
++
it
)
{
cout
<<
(
string
)
*
it
<<
"
\n
"
;
}
Mat
R
,
T
;
cout
<<
"reading R and T"
<<
endl
;
fs
[
"R"
]
>>
R
;
fs
[
"T"
]
>>
T
;
cout
<<
"R = "
<<
R
<<
"
\n
"
;
cout
<<
"T = "
<<
T
<<
endl
;
MyData
m
;
fs
[
"mdata"
]
>>
m
;
cout
<<
"read mdata
\n
"
;
cout
<<
m
<<
endl
;
cout
<<
"attempting to read mdata_b
\n
"
;
fs
[
"mdata_b"
]
>>
m
;
cout
<<
"read mdata_b
\n
"
;
cout
<<
m
<<
endl
;
}
cout
<<
"Try opening "
<<
filename
<<
" to see the serialized data."
<<
endl
;
return
0
;
}
samples/cpp/imagelist_creator.cpp
0 → 100644
View file @
2e913625
/*this creates a yaml or xml list of files from the command line args
*/
#include "opencv2/core/core.hpp"
#include <string>
#include <iostream>
using
std
::
string
;
using
std
::
cout
;
using
std
::
endl
;
using
namespace
cv
;
void
help
(
char
**
av
)
{
cout
<<
"usage:
\n
"
<<
av
[
0
]
<<
" imagelist.yaml *.png
\n
"
<<
"Try using different extensions.(e.g. yaml yml xml xml.gz etc...)
\n
"
<<
"This will serialize this list of images or whatever with opencv's FileStorage framework"
<<
endl
;
}
int
main
(
int
ac
,
char
**
av
)
{
if
(
ac
<
3
)
{
help
(
av
);
return
1
;
}
string
outputname
=
av
[
1
];
FileStorage
fs
(
outputname
,
FileStorage
::
WRITE
);
fs
<<
"images"
<<
"["
;
for
(
int
i
=
2
;
i
<
ac
;
i
++
){
fs
<<
string
(
av
[
i
]);
}
fs
<<
"]"
;
return
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