加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

opencv读写xml文件

发布时间:2020-12-15 23:40:05 所属栏目:百科 来源:网络整理
导读:int sub_test_opencv_xml_write( void ) { //创建文件存储对象 CvFileStorage*fs=cvOpenFileStorage( "test.xml" ,CV_STORAGE_WRITE); //写注释 cvWriteComment(fs, "测试写XML文件" ,1); //开始写结构,类型是图map,也就是有名字的无序节点集合 cvStartWri
  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"> }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读