How to save contour object to file

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to save contour object to file

pink_edward@ymail.com
I want to save contour to file and read it out, but don't know how
This's is my test code, please help

IplImage * pSrcImg = cvLoadImage("7Home.bmp",CV_LOAD_IMAGE_GRAYSCALE);
CvSize ImgSize = cvSize(pSrcImg->width, pSrcImg->height);
IplImage * pBinImg = cvCreateImage( ImgSize, IPL_DEPTH_8U, 1);
IplImage* pContourImg = cvCreateImage( ImgSize, IPL_DEPTH_8U, 1);
CvMemStorage * pStorage = NULL;
CvSeq * pContour = 0;
cvThreshold(pSrcImg, pBinImg, 90, 255, CV_THRESH_BINARY);
cvRectangle(pContourImg,cvPoint(0,0),cvPoint(pContourImg-
>width,pContourImg->height),CV_RGB(0,0,0),CV_FILLED);

pStorage = cvCreateMemStorage(0);
cvFindContours( pBinImg, pStorage, &pContour, sizeof(CvContour),
CV_RETR_TREE, CV_CHAIN_APPROX_NONE, cvPoint(0,0));

//save contours to file
CvFileStorage *fs = cvOpenFileStorage("test.yml",0,CV_STORAGE_WRITE);
cvWrite(fs,"Contour",pContour,cvAttrList(0,0));
cvReleaseFileStorage(&fs);

//read from file and check it
fs = cvOpenFileStorage("test.yml",0,CV_STORAGE_READ);
CvFileNode *fn = cvGetFileNodeByName(fs,0,"Contour");