Serialization of a vector of vectors (Bug #4392)


Added by Philipp Hasper almost 10 years ago. Updated over 9 years ago.


Status:New Start date:2015-06-09
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
Affected version:branch 'master' (3.0-dev) Operating System:Any
Difficulty:Medium HW Platform:Any
Pull request:

Description

Serializing nested vectors using the persistence framework:

std::vector<std::vector<int> > ppp;
ppp.push_back(std::vector<int>(2)); ppp[0][0] = 2; ppp[0][1] = 2;
ppp.push_back(std::vector<int>(3)); ppp[1][0] = 3; ppp[1][1] = 3;  ppp[1][2] = 3;
cv::FileStorage wfs("experiment.yml", cv::FileStorage::WRITE);
wfs << "points" << ppp;
wfs.release();

results in
%YAML:1.0
points:
   - 2
   - 2
   - 3
   - 3
   - 3

which is obviously wrong - the two child vectors are just appended. A subsequent deserialization (fs["points"] >> ppp) will even crash.

This is because the first, enclosing vector is written using void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ).
But the child vectors are written using void write( FileStorage& fs, const std::vector<_Tp>& vec ) which does not introduce a nested structure.


History

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/5013

Also available in: Atom PDF