Sorry, this content is no longer available

Ask Your Question
0

FileStorage Documetation Wrong/Failing

asked May 25 '13

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.

Preview: (hide)

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 (May 28 '13)edit

1 answer

Sort by » oldest newest most voted
1

answered May 25 '13

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 }
Preview: (hide)

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 (May 27 '13)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 (May 27 '13)edit

Question Tools

Stats

Asked: May 25 '13

Seen: 336 times

Last updated: May 25 '13