Ask Your Question

Revision history [back]

Filestorage and vector

Hi, I have read http://docs.opencv.org/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.html 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 :

image description and after contour with only one contour :

image description

I have check data in regular file and i can see

image description

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 : image description

I don't understand why I cannot see in yml file contour point like in my regular file. Thanks you for your help