#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; } 本文转自gnuhpc博客园博客,原文链接http://www.cnblogs.com/gnuhpc/archive/2012/07/02/2573808.html,如需转载请自行联系原作者