At the moment, I solved this by simply not using OpenCV FileStorage. Here is what I did to store the vector of the Point vector, since there are good procedures for printing vectors.
bool writeVectorVectorPoint(string fname, vector<vector<Point> > vvP) { ofstream fsOut; vector<vector<Point> >::iterator p; fsOut.open(fname.c_str()); if(fsOut.fail()) { cout << "Failed to open " << fname << endl; return(false); } for(p = vvP.begin(); p != vvP.end(); p++) { fsOut << (*p) << endl; } fsOut.close(); return(true); }
Reading them back is a little trickier, but still not tricky. If anyone sees any optimizations, let me know, as I suspect there is a better (or at least more elegant) solution.
bool readVectorVectorPoint(string fname, vector<vector<Point> >& vvP) { ifstream fsIn; fsIn.open(fname.c_str()); if(fsIn.fail()) { cout << "Failed to open: " << fname << endl; return(false); } Point pt; vector<Point> vPt; vector<Point>::iterator p; string line; while(getline(fsIn, line)) { cout << line << endl; string ptStr; stringstream s(line.substr(1,line.size()-1)); vPt.clear(); while(getline(s, ptStr, ';')) { stringstream s1(ptStr); string lastStr; getline(s1, lastStr, ','); pt.x = atoi(lastStr.c_str()); getline(s1, lastStr, ','); pt.y = atoi(lastStr.c_str()); vPt.push_back(pt); } vvP.push_back(vPt); } fsIn.close(); return(true); }
source share