opencv 操作XML,读写数组

自己整理的,使用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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值