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
) after cleaning the build directory.
I'm running a Win 7 x64 with VS2012 as a compiler.
Many thanks,
Viktor
fs << "{:"
// it needs a colon thereI have tried that already. Still triggers
CV_Error
. Also, the docs state:To store a mapping/sequence in a compact form, put ”:” after the opening character
. So the colon operator is anyway just a YAML specific thing.Are you able to reproduce this behaviour with the latest master branch @berak?
the colon also applies, when you save to xml
From what I've read, they are being ignored when writing XML. The 2.4.11 doc reads:
When the data is written to XML, those extra ”:” are ignored
. Anyway, I don't think this is the cause of my problems, since I receive the exact same error no matter if colon present or not.Anybody able to reproduce the error?