Filestorage and vector
Hi, I have read http://docs.opencv.org/doc/tutorials/... about Filestorage. Now I want to save in a yml file image and contour. When I open yml file I 've got image stat and stag :
and after contour with only one contour :
I have check data in regular file and i can see
My program :
int main(int ac, char** av)
{
Mat m,mThresh,mCmp;
Mat statMom,statG;
Mat imCtr;
vector<vector<cv::Point> >pointCtr;
vector<cv::Vec4i> arbo;
m=imread("C:\\tmp\\small.tif",cv::IMREAD_UNCHANGED);
threshold( m, mThresh, 50,255,THRESH_BINARY);
connectedComponentsWithStats(mThresh, mCmp,statMom,statG,8, CV_32S);
mCmp.copyTo(imCtr);
findContours(imCtr, pointCtr,arbo, cv::RETR_CCOMP, cv::CHAIN_APPROX_NONE, cv::Point(0,0));
cv::FileStorage fs("test.yml", cv::FileStorage::WRITE);
fs<<"Image"<<mCmp;
fs<<"Stat"<<statMom;
fs<<"Pos"<<statG;
fs<<"Ctr"<<"["<<pointCtr<<"]";
fs<<"Arbo"<<"["<<arbo<<"]";
fs.release();
ofstream gFic("test.txt");
vector<vector<cv::Point> >::iterator itCtr;
gFic<<"**********POINT***************"<<endl;
int indCtr=0;
for (itCtr=pointCtr.begin();itCtr!=pointCtr.end();itCtr++)
{
vector<cv::Point> ::iterator itPt;
gFic<<"Contour "<<indCtr<<" ";
for (itPt=itCtr->begin();itPt!=itCtr->end();itPt++)
{
gFic<<itPt->x<<" "<<itPt->y<<" ";
}
gFic<<endl;
indCtr++;
}
vector<cv::Vec4i>::iterator ita;
gFic<<"**********ARBO***************"<<endl;
for (ita=arbo.begin();ita!=arbo.end();ita++)
{
gFic<<*ita<<" ";
}
gFic<<endl;
}
and my data :
I don't understand why I cannot see in yml file contour point like in my regular file. Thanks you for your help
Finally I have missed some lines in doc. I think it's not possible to write a vector<vector> in FileStorage. With this new code only one vector is written and everything is OK in yml file
To bad i didnt see this earlier. Indeed FileStorage only allows writing up to the vector structure. A wrapped structure around it should be manually unwrapped before writing to a FileStorage element.