opencv学習-読み書きxml
この記事を転載しますhttp://blog.csdn.net/jarvischu/article/details/8481510
#include "stdafx.h"
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// XML
CvFileStorage* fs = cvOpenFileStorage("jarvischu.xml",
0, // , NULL,
CV_STORAGE_WRITE,
"GB2312"//
);
//
cvWriteInt(fs,"frame_count",10); //-- Int
cvWriteReal(fs,"pi",3.14); //-- Float
//--
cvStartWriteStruct(fs,"frame_size",CV_NODE_MAP,"id_size" );// ( )
cvWriteInt(fs,"width",320);
cvWriteInt(fs,"height",200);
cvEndWriteStruct(fs);
cvStartWriteStruct(fs,"author_info",CV_NODE_SEQ,"id_author");//
cvWriteString(fs,0,"JarvisChu");
cvWriteString(fs,0,"China");
cvEndWriteStruct(fs);
//--
unsigned char vec[]={1,2,3,4,5,6,7,8,9};
CvMat mat = cvMat(3,3,CV_8UC1,vec);
cvWrite(fs,"Matrix",&mat);
//--
cvWriteComment(fs,"This is a example for operatoring the xml file",0);// 0 ,0
//
cvReleaseFileStorage(&fs);
// XML
fs = cvOpenFileStorage("jarvischu.xml",
0, // , NULL,
CV_STORAGE_READ,
"GB2312"//
);
//
int f = cvReadIntByName(fs,0,"frame_count",0);// Int
//--
CvFileNode* fn = cvGetFileNodeByName(fs,0,"frame_size"); // ( , )
int width = cvReadIntByName(fs,fn,"width"); //
int height = cvReadIntByName(fs,fn,"height");
//--
fn = cvGetFileNodeByName(fs,0,"author_info");//
CvSeq* seq = fn->data.seq; //
const char* name = cvReadString((CvFileNode*)cvGetSeqElem(seq,0));// 0
const char* country = cvReadString((CvFileNode*)cvGetSeqElem(seq,1));// 1
cout<<"frame_count:"<<f<<endl<<"width:"<<width<<endl<<"height"<<height<<endl\
<<"name:"<<name<<endl<<"country:"<<country<<endl;
return 0;
}