forked from oreillymedia/Learning-OpenCV-3_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_08-03.cpp
56 lines (42 loc) · 1.49 KB
/
example_08-03.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Example 8-3. Using cv::FileStorage to read a .yml file
//
#include <opencv2/opencv.hpp>
using namespace std;
int main(int argc, char** argv) {
cout << "\nExample 8-3. Using cv::FileStorage to read a .yml file"
<< "\nCall:\n"
<< argv[0] << endl;
cv::FileStorage fs2("test.yml", cv::FileStorage::READ);
// first method: use (type) operator on FileNode.
//
int frameCount = (int)fs2["frameCount"];
// second method: use cv::FileNode::operator >>
//
std::string date;
fs2["calibrationDate"] >> date;
cv::Mat cameraMatrix2, distCoeffs2;
fs2["cameraMatrix"] >> cameraMatrix2;
fs2["distCoeffs"] >> distCoeffs2;
cout << "frameCount: " << frameCount << endl
<< "calibration date: " << date << endl
<< "camera matrix: " << cameraMatrix2 << endl
<< "distortion coeffs: " << distCoeffs2 << endl;
cv::FileNode features = fs2["features"];
cv::FileNodeIterator it = features.begin(), it_end = features.end();
int idx = 0;
std::vector<uchar> lbpval;
// iterate through a sequence using FileNodeIterator
for( ; it != it_end; ++it, idx++ ) {
cout << "feature #" << idx << ": ";
cout << "x=" << (int)(*it)["x"]
<< ", y=" << (int)(*it)["y"]
<< ", lbp: (";
// ( Note: easily read numerical arrays using FileNode >> std::vector. )
//
(*it)["lbp"] >> lbpval;
for( int i = 0; i < (int)lbpval.size(); i++ )
cout << " " << (int)lbpval[i];
cout << ")" << endl;
}
fs2.release();
}