|||
void my_opencv_xml_write(void)
{
char pID[] = "0001";
int featureCount = 10;
// 具体数据
int _record[]={30000,4200,50090};
//创建文件存储对象
CvFileStorage *fs=cvOpenFileStorage("test.xml",0,CV_STORAGE_WRITE);
// 写注释
cvWriteComment(fs,"Person Feature Analysis NO.0001",1);
// 开始写结构,类型是图map,也就是有名字的无序节点集合
cvStartWriteStruct(fs, "Person", CV_NODE_MAP, pID , cvAttrList(NULL,NULL));
{
//1
cvWriteComment(fs,"Face Feature NO.001",1);
// 开始写结构,类型是图map,也就是有名字的无序节点集合
cvStartWriteStruct(fs, "Face_Feature", CV_NODE_MAP, "001", cvAttrList(NULL,NULL));
{
//注释Properties
cvWriteComment(fs,"MAPTYPE Properties",1);
// 开始写结构,类型是图map,也就是有名字的无序节点集合
cvStartWriteStruct(fs, "Properties", CV_NODE_MAP, NULL, cvAttrList(NULL,NULL));
// 注释
cvWriteComment(fs,"MAPType, name, age",0);
// 姓名
cvWriteString(fs,"name","liuyue", 0);
// 年龄
cvWriteInt(fs,"age",18);
// 特征值
cvWriteInt(fs,"feature_count",featureCount);
// 结束Properties
cvEndWriteStruct(fs);
}
{
// 注释Feature
cvWriteComment(fs,"SEQType Feature",1);
// 开始写结构,类型是序列sequence,无名字的有序节点集合
cvStartWriteStruct(fs,"Feature",CV_NODE_SEQ, NULL, cvAttrList(NULL,NULL));
// 前3条记录
cvWriteRawData(fs,_record,3,"i");
// 第4条记录,注意无名字
cvWriteInt(fs,0,6100);
// 结束Feature
cvEndWriteStruct(fs);
}
// 结束1
cvEndWriteStruct(fs);
}
{
//2
cvWriteComment(fs,"Face Feature NO.002",1);
// 开始写结构,类型是图map,也就是有名字的无序节点集合
cvStartWriteStruct(fs, "Face_Feature", CV_NODE_MAP, "002", cvAttrList(NULL,NULL));
{
//注释Properties
cvWriteComment(fs,"MAPTYPE Properties",1);
// 开始写结构,类型是图map,也就是有名字的无序节点集合
cvStartWriteStruct(fs, "Properties", CV_NODE_MAP, NULL, cvAttrList(NULL,NULL));
// 注释
cvWriteComment(fs,"MAPType, name, age",0);
// 姓名
cvWriteString(fs,"name","liuyue", 0);
// 年龄
cvWriteInt(fs,"age",18);
// 特征值
cvWriteInt(fs,"feature_count",featureCount);
// 结束Properties
cvEndWriteStruct(fs);
}
{
// 注释Feature
cvWriteComment(fs,"SEQType Feature",1);
// 开始写结构,类型是序列sequence,无名字的有序节点集合
cvStartWriteStruct(fs,"Feature",CV_NODE_SEQ, NULL, cvAttrList(NULL,NULL));
// 前3条记录
cvWriteRawData(fs,_record,3,"i");
// 第4条记录,注意无名字
cvWriteInt(fs,0,6100);
// 结束Feature
cvEndWriteStruct(fs);
}
// 结束2
cvEndWriteStruct(fs);
}
// 结束
cvEndWriteStruct(fs);
// 释放文件存储对象
cvReleaseFileStorage(&fs);
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-23 22:49
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社