Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2\core\core.hpp>
- #include <opencv2\highgui\highgui.hpp>
- #include <iostream>
- #include <string>
- using namespace cv;
- using namespace std;
- int main(int ac, char** av)
- {
- string filename = av[1];
- {
- Mat R = Mat_<uchar>::eye(3,3),
- T = Mat_<double>::zeros(3,1);
- int sz[3] = {2,2,2};
- Mat L(3,sz, CV_8UC(1), Scalar::all(0));
- Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
- Mat M = imread("image.jpg");
- FileStorage fs(filename, FileStorage::WRITE);
- fs << "iterationNr" << 100;
- fs << "strings" << "[";
- fs << "image1.jpg" << "Awasomeness" << "baboon.jpg";
- fs << "]";
- fs << "Mapping";
- fs << "{" << "One" << 1;
- fs << "Two" << 2 << "}";
- fs << "R" << R;
- fs << "T" << T;
- fs << "C" << C;
- fs << "M" << M;
- fs.release();
- cout << "Write Done." << endl;
- }
- { // read
- cout << endl << "Reading: " << endl;
- FileStorage fs;
- fs.open(filename, FileStorage::READ);
- int itNr;
- itNr = fs["iterationNr"];
- cout << itNr << endl;
- if( !fs.isOpened() )
- {
- cerr << "Failed to open" << filename << endl;
- return 1;
- }
- FileNode n = fs["strings"];
- if (n.type() != FileNode::SEQ)
- {
- cerr << "strings is not a sequence ! FAIL";
- }
- FileNodeIterator it = n.begin(), it_end = n.end();
- for (;it != it_end;++it)
- cout << (string)*it << endl;
- n = fs["Mapping"];
- cout<< "Two " << (int)(n["Two"]) << "; ";
- cout<< "One " << (int)(n["One"]) << endl << endl;
- Mat M;
- fs["M"] >> M;
- cout << endl << "M =" << M << endl;
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement