【OpenCV学习】XMl文件存储

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/

 

#include "highgui.h"
#include "cv.h"
#include "cxcore.h"
#include <iostream>
#include <iomanip>

using namespace std;

int main(void)
{
    CvMat *mat=cvCreateMat(3,3,CV_32SC1);
    cvSetIdentity(mat);
    CvMemStorage *memstorage =cvCreateMemStorage(0);
    //内存存储器(数据写入时需要)
    CvFileStorage *fs_write_xml = cvOpenFileStorage("mat.xml",memstorage,CV_STORAGE_WRITE);
    CvFileStorage *fs_write_yml = cvOpenFileStorage("mat.yml",memstorage,CV_STORAGE_WRITE);
    //文件存储结构
    cvWriteComment(fs_write_xml,"mat_xml",1);
    //添加注释
    cvWrite(fs_write_xml,"CvMat",mat,cvAttrList(NULL,NULL));
    //将数据写到XML文件中
    cvReleaseFileStorage(&fs_write_xml);
    
    cvWriteComment(fs_write_yml,"mat_yml",1);
    //添加注释
    cvWrite(fs_write_yml,"CvMat",mat,cvAttrList(NULL,NULL));
    //将数据写到XML文件中
    cvReleaseFileStorage(&fs_write_yml);

    cvReleaseMemStorage(&memstorage);
    cvReleaseMat(&mat);

    return 0;
}
posted @ 2012-07-02 22:45  gnuhpc  阅读(2438)  评论(0编辑  收藏  举报