自己整理的,使用OPENCV读写XML文件的数组,不是很完善,欢迎拍砖!
//将图片存为xml文件程序:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include <highgui.h>
#include "cxcore.h"
struct CatInfo {
string Title;
int TotalCnt;
} ;
void my_opencv_xml_write(void);
int main()
{
struct CatInfo Cats[3];//类别数组
Cats[0].Title= "S01";
Cats[0].TotalCnt=10;
Cats[1].Title= "S02";
Cats[1].TotalCnt=20;
Cats[2].Title= "S03";
Cats[2].TotalCnt=30;
CvFileStorage* fs = cvOpenFileStorage( "upimg_matched_points.xml", 0, CV_STORAGE_WRITE );
if(!fs)
{
return -1;
}
cvStartWriteStruct(fs, "CatInfo", CV_NODE_MAP);//对应于 读取时父节点的子节点
char SN[256];//序号
int max = 3;//类别数组元素个数
for(int i=0; i<max; i++)
{
sprintf(SN, "%d", i);
char CatType[256] = "CatInfo";//初始化
char* Key = strcat(CatType, SN);//拼接关键字,以免重复
cvStartWriteStruct(fs, Key, CV_NODE_MAP, Cats[i].Title.c_str());//子节点的子节点,参数2:【不能重名】
cvW