opencv读写xml文件

  1. intsub_test_opencv_xml_write(void)
  2. {
  3. //创建文件存储对象
  4. CvFileStorage*fs=cvOpenFileStorage("test.xml",CV_STORAGE_WRITE);
  5. //写注释
  6. cvWriteComment(fs,"测试写XML文件",1);
  7. //开始写结构,类型是图map,也就是有名字的无序节点集合
  8. cvStartWriteStruct(fs,"Employee",CV_NODE_MAP);
  9. //注释
  10. cvWriteComment(fs,"MAP类型,姓名,年龄,薪水",1);
  11. //姓名
  12. cvWriteString(fs,"name","刘越");
  13. //年龄
  14. cvWriteInt(fs,"age",18);
  15. //薪水
  16. cvWriteReal(fs,"salary",2780.3);
  17. //销售次数
  18. "sales_count",4);
  19. //销售具体数据
  20. intsales_record[]={30000,4200,50090};
  21. //注释
  22. "SEQ类型,销售记录",0); background-color:inherit">//开始写结构,类型是序列sequence,无名字的有序节点集合
  23. cvStartWriteStruct(fs,"sales_record",CV_NODE_SEQ);
  24. //前3条销售记录
  25. cvWriteRawData(fs,sales_record,3,"i");
  26. //第4条销售记录,注意无名字
  27. cvWriteInt(fs,6100);
  28. //结束
  29. cvEndWriteStruct(fs);
  30. }
  31. "MAP类型,亲友",0); background-color:inherit">//开始
  32. "Parent",CV_NODE_MAP);
  33. //父亲
  34. cvWriteString(fs,"father","杨舜");
  35. //母亲
  36. "mother","王娟");
  37. //结束
  38. cvEndWriteStruct(fs);
  39. //释放文件存储对象
  40. cvReleaseFileStorage(&fs);
  41. }
  42. intsub_test_opencv_xml_read(void)
  43. {
  44. //文件节点
  45. CvFileNode*node,*node2;
  46. char*str;
  47. intcount;
  48. int*d;
  49. //cve_dm.debug_break();
  50. //打开XML文件
  51. //获得第一层数据节点
  52. node=cvGetFileNodeByName(fs,"Employee");
  53. str=cvReadStringByName(fs,node,"name");
  54. printf("\n姓名=%s",str);
  55. printf("\n年龄=%d",cvReadIntByName(fs,"age"));
  56. printf("\n薪水=%g",cvReadRealByName(fs,"salary"));
  57. count=cvReadIntByName(fs,"sales_count");
  58. printf("\n销售%d条",count);
  59. d=cvAlloc(sizeof(int)*count);
  60. if(d)
  61. inti;
  62. node2=cvGetFileNodeByName(fs,"sales_record");
  63. if(node2)
  64. cvReadRawData(fs,node2,d,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> printf("\n销售记录=");
  65. for(i=0;i<count;i++)
  66. printf("%d,",d[i]);
  67. cvFree(&d);
  68. //获得第二层节点
  69. "Parent");
  70. printf("\n根节点=%s",cvGetFileNodeName(node));
  71. str=cvReadStringByName(fs,"father");
  72. printf("\n父亲=%s",str);
  73. "mother");
  74. printf("\n母亲=%s",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇