Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Confusion over FileStorage syntax

Hallo friends,

I'm confused over how to use FileStorage in order to write a sequence of mappings to a file.
Here's an example:

vector<pair<uint, Point>> vec; // holds results of video analysis
// append pairs to vec...
FileStorage fs(file, FileStorage::WRITE);   
fs << "Positions" << "[";
    for (Result::iterator i = vec.begin(); i != vec.end(); ++i)
    {
        fs << "{" 
            << "Frame" << (int)i->first
            << "X" << i->second.x 
            << "Y" << i->second.y 
            << "}";
    }
fs << "]";

When I'm running the above code I trigger the following CV_Error (persistence.hpp:1064):

if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP )
        CV_Error( Error::StsError, "No element name has been given" );

While trying to write the first element of the mapping. Of course I've checked the docs (see: http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html) but was suprised to see, that they basically do the exact same thing there.
Have they changed the syntax in OpenCV3.0 or am I overlooking something here?

I've already recompiled the current master branch (faa6684) prior to cleaning the build directory.
I'm running a Win 7 x64 with VS2012 as a compiler.

Many thanks,
Viktor

Confusion over FileStorage syntax

Hallo friends,

I'm confused over how to use FileStorage in order to write a sequence of mappings to a file.
Here's an example:

vector<pair<uint, Point>> vec; // holds results of video analysis
// append pairs to vec...
FileStorage fs(file, FileStorage::WRITE);   
fs << "Positions" << "[";
    for (Result::iterator i = vec.begin(); i != vec.end(); ++i)
    {
        fs << "{" 
            << "Frame" << (int)i->first
            << "X" << i->second.x 
            << "Y" << i->second.y 
            << "}";
    }
fs << "]";

When I'm running the above code I trigger the following CV_Error (persistence.hpp:1064):

if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP )
        CV_Error( Error::StsError, "No element name has been given" );

While trying to write the first element of the mapping. Of course I've checked the docs (see: http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html) but was suprised to see, that they basically do the exact same thing there.
Have they changed the syntax in OpenCV3.0 or am I overlooking something here?

I've already recompiled the current master branch (faa6684) prior to after cleaning the build directory.
I'm running a Win 7 x64 with VS2012 as a compiler.

Many thanks,
Viktor