Save Xml file directory problem. Openframeworks and fileStorage [closed]

asked 2018-07-18 05:25:44 -0600

nouIgnasi gravatar image

updated 2018-07-18 05:41:32 -0600

Hello,

I'm working on an OpenFrameworks app, where I am using the OpenCV addon (ofxOpenCV). The problem occurs when I try to save the ANN parameters on a xml file. The xml does not appear on the entire system. I try another version with a simple matrix and the result is the same.

I am using Xcode (C++). OpenCV version : 3.4.1.

I try the following code and return the weights (one of the ANN parameters) so, maybe somewhere there is the xml file...

    FileStorage fs;
    fs.open("mlp.xml", FileStorage::WRITE);
    ann[0]->write(fs);
    fs.release();

    FileStorage opencv_file("mlp.xml", FileStorage::READ);
    Ptr<ANN_MLP> nn = ANN_MLP::create();

    nn->read(opencv_file.root());
    cout << nn->getWeights(0) <<endl; //RETURN THE WEIGHTS
    opencv_file.release();

I also try to read by fileNode and the output matrix is empty.

The idea is to load/save (write/read) different xml files (or other types of files) to set different ANN parameters.

Any idea?

Thank you! Ignasi.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by nouIgnasi
close date 2018-07-18 06:05:36.811446

Comments

OpenCV version : 2.4.9. -- ouch.

please check again. above code would require opencv 3.x

maybe you also should check fs.isOpened()

trying with an absolute path would be another idea.

berak gravatar imageberak ( 2018-07-18 05:26:37 -0600 )edit
1

Sorry, version edited (3.4.1). I also check if it is opened and it is ok.

     FileStorage fs;
    fs.open("mlp.xml", FileStorage::WRITE);
    if (!fs.isOpened())
    {
        cout << "Not opened" << endl;
    }else{
        cout << "fs is opended" <<endl;
    ann[0]->write(fs);
    fs.release();
    }
    FileStorage opencv_file("mlp.xml", FileStorage::READ);


    if (!opencv_file.isOpened())
    {
        cout << "Not oppened" << endl;
    }else{
        cout << "opencvfile is opended" <<endl;

    Ptr<ANN_MLP> nn = ANN_MLP::create();

    nn->read(opencv_file.root());
    cout << nn->getWeights(0) <<endl; //RETURN THE WEIGHTS
    opencv_file.release();
    }
nouIgnasi gravatar imagenouIgnasi ( 2018-07-18 05:44:07 -0600 )edit

Absolute path (but inside the project folder). Thank you! Thank you! Thank you! and Thank you!

nouIgnasi gravatar imagenouIgnasi ( 2018-07-18 06:03:28 -0600 )edit