Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileStorage Capabilities #403

Closed
fdncred opened this issue Nov 3, 2017 · 1 comment
Closed

FileStorage Capabilities #403

fdncred opened this issue Nov 3, 2017 · 1 comment
Labels
enhancement New feature or request

Comments

@fdncred
Copy link

fdncred commented Nov 3, 2017

Summary of your issue

I can't figure out how to duplicate this FileStorage example. Is there a way?
https://docs.opencv.org/master/d6/d03/filestorage_8cpp-example.html

These are the specific sections that I'm interested in.

//write
  {
    FileStorage fs(filename, FileStorage::WRITE);
    cout << "writing images\n";
    fs << "images" << "[";
    fs << "image1.jpg" << "myfi.png" << "../data/baboon.jpg";
    cout << "image1.jpg" << " myfi.png" << " ../data/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";   //Show default behavior for empty matrix
    fs["mdata_b"] >> m;
    cout << "read mdata_b\n";
    cout << m << endl;
  }
@shimat shimat added the enhancement New feature or request label Apr 27, 2018
@shimat
Copy link
Owner

shimat commented Apr 27, 2018

I am sorry for the late reply 🙇

This will be fixed by #484 except custom struct support.
https://github.com/shimat/opencvsharp/blob/57e4b58230abd504fb0ca0913e9cb7643d5fc78b/test/OpenCvSharp.Tests/core/FileStorageTest.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants