Ask Your Question
0

FileStorage Documetation Wrong/Failing

asked 2013-05-25 11:22:55 -0500

pistorinoj gravatar image

I am trying to use FileStorage. The sample code in the documentation crashes when it reaches the first "[" bracket. Also, the sample code specifies a "yml" file type but eh text in the documentation states that the sample code will output an "xml" file.

I have tried several variations on the sample code (specifying xml instead of yml, putting a ":" after the bracket, etc.) but still no luck.

        FileStorage fs(tFileName,FileStorage::WRITE);
        std::list<cvImages>::iterator itl;

        if(fs.isOpened())
        {
            fs << "style name";
            fs << "images" << "[";

            for(itl = MatchInstance->begin(); itl != MatchInstance->end(); ++itl)
            {
                fs << "{:";
                fs << "ImageID" << (*itl).ImageID;
                fs << "Height" << (*itl).ImageID;
                fs << "Width" << (*itl).ImageID;
                fs << "AnalysisFrameType" << (*itl).ImageID;
                fs << "ShowImageType" << (*itl).ImageID;
                fs << "ImageSize" << (*itl).ImageID;
                fs << "}";
            }
            fs << "]";
        }
        fs.release();

Any help great appreciated.

edit retag flag offensive close merge delete

Comments

Having checked this, another issue is that FileStorage cannot accept a string with a space as the key. Thus, "style name" will not work because "style" will be treated as the key and "name" will be treated as the value.

pistorinoj gravatar imagepistorinoj ( 2013-05-27 18:49:11 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-25 11:50:15 -0500

berak gravatar image

FileStorage is basically a key-value store.

fs << key << value;  // pseudo

you break it in the very first line:

fs << "style name";  // now, that's the "key", and where's the "value" ?

do you need that line at all ? or did you mean this ? :

fs << "style" << "name";

    FileStorage fs("my.yml",FileStorage::WRITE);
    if(fs.isOpened())
    {
        fs << "style" << "name";
        fs << "images" << "[";
        for(int i=0; i<3; i++)
        {
            fs << "{:";
            fs << "ImageID" << i;
            fs << "Height" << i;
            fs << "Width" << i;
            fs << "}";
        }
        fs << "]";
    }

    fs.release();

%YAML:1.0
style: name
images:
   - { ImageID:0, Height:0, Width:0 }
   - { ImageID:1, Height:1, Width:1 }
   - { ImageID:2, Height:2, Width:2 }
edit flag offensive delete link more

Comments

Thanks. I originally had a value there that was to be stored (a string) but that also seemed to cause a problem. Then I took the value away and that got past the line but moved to the next one. In any event, that was the problem so thanks. I am also wrong about the documentation? The example says "yml" but the text says that it will output xml.

pistorinoj gravatar imagepistorinoj ( 2013-05-27 16:10:11 -0500 )edit

to my knowledge: FileStorage fs("my.xml",FileStorage::WRITE);

will write xml.

anything else , like "my.bla", "my.bad", will result in yml

berak gravatar imageberak ( 2013-05-27 16:13:47 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-05-25 11:22:55 -0500

Seen: 129 times

Last updated: May 25 '13