如何使用opencv的c++接口来读取、写结构体数组到yml文件中
2015-07-17 14:48
477 查看
引用地址
http://blog.csdn.net/jia_zhengshen/article/details/12910299
参考地址:
http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html#filestorage-writeraw
优先选用yml而不是xml
结构体数值支持类型解释:
http://blog.csdn.net/jia_zhengshen/article/details/12910299
参考地址:
http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html#filestorage-writeraw
优先选用yml而不是xml
#include<opencv2\opencv.hpp> #include<time.h> using namespace std; using namespace cv; typedef struct _t{ int x; int y; //不支持size_t,unsigned等无符号类型数值的存储,目前只支持int,float,double,string类型(具体解释在代码后) double c; }t; #include "opencv2/opencv.hpp" #include <time.h> using namespace cv; int main(int, char** argv) { FileStorage fs("test.xml", FileStorage::WRITE); fs << "frameCount" << 5; time_t rawtime; time(&rawtime); fs << "features" << "[";//结构数组开始的标志 for( int i = 0; i < 3; i++ ) { int x = rand() % 640;//使用随机数产生数值 int y = rand() % 480; double c = rand()*0.3; fs<<"{:";//一个结构体开始的标志,yml才有:,xml自动忽略 fs<<"x"<<x; fs<<"y"<<y; fs<<"c"<<c; fs<<"}";//结构体结束的标志,自动换行 } fs << "]";//结构体数组结束的标志。 fs.release(); //读取xml文件。 cv::FileStorage fs2("test.xml",FileStorage::READ); FileNode features = fs2["features"];//读取结构体数组 FileNodeIterator fni = features.begin(); FileNodeIterator fniEnd = features.end(); for(;fni != fniEnd;fni++)//遍历 { t myT ; myT.x = (int )(*fni)["x"]; myT.y = (int )(*fni)["y"]; myT.c = (double)(*fni)["c"]; cout<<"x"<<myT.x<<" "<<"y"<<myT.y<<" c"<<myT.c<<endl; } return 0; }
结构体数值支持类型解释:
CV_EXPORTS_W void write( FileStorage& fs, const string& name, int value ); CV_EXPORTS_W void write( FileStorage& fs, const string& name, float value ); CV_EXPORTS_W void write( FileStorage& fs, const string& name, double value ); CV_EXPORTS_W void write( FileStorage& fs, const string& name, const string& value );
相关文章推荐
- malloc和calloc的区别
- 【c++】模拟实现boost库下的scoped_array
- c++课程实训-银行系统
- C/C++程序设计05(泛型编程、容器、STL)
- C++课程实训——银行系统
- c++课程实训 银行储蓄系统
- <2015年大一C++实训项目>银行储蓄系统
- C++11的一些功能
- 【STL】C++使用STL处理替换字符串操作。
- 黑马程序员-C语言基础知识-流程控制
- C++ 全局对象构造和析构
- ##..C++程序设计项目实训——银行储蓄系统
- 转:关于C++ const 的全面总结
- VC++中MCI播放音频文件 【转】
- firefox浏览器调用C++编写的ocx的方法
- NULL和nullptr和nil和Nil还有NSNull
- C++中的delete浅析
- 用c语言编写身份证号码是否合法
- C++面试知识点总结
- Manacher算法-求字符串中最长回文串