打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
OpenCV 2.4.3 Cheat Sheet学习 数据的输入和输出
// wenjianduxie.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "stdafx.h"
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
#include <iostream>  


using namespace cv;  
using namespace std;  

int main( int argc, char** argv )

{      //1.    将数据写入YAML(或XML)
//注意,在OpenCV中,无论读写,文件的格式均由指定的后缀名确定。示例:
/*
FileStorage fs("test.yml", FileStorage::WRITE);
fs << "i" << 5 << "r" << 3.1 << "str" << "ABCDEFGH";
fs << "mtx" << Mat::eye(3,3,CV_32F);
fs << "mylist" << "[" << CV_PI << "1+1" << "{:" << "month" << 12 << "day" << 31 << "year" << 1969 << "}" << "]";
fs << "mystruct" << "{" << "x" << 1 << "y" << 2 << "width" << 100 << "height" << 200 << "lbp" << "[:";
const uchar arr[] = {0, 1, 1, 0, 1, 1, 0, 1};
fs.writeRaw("u", arr, (int)(sizeof(arr)/sizeof(arr[0])));
fs << "]" << "}";
*/

///*
//1.    将数据读回 这段代码把上面写入文件的数据再读回来。
FileStorage fs("test.yml", FileStorage::READ);
int i1 = (int)fs["i"];
double r1 = (double)fs["r"];
string str1 = (string)fs["str"];
Mat M;
fs["mtx"] >> M;
cout<<M<<endl;
FileNode tl = fs["mylist"];
CV_Assert(tl.type() == FileNode::SEQ && tl.size() == 3);
double tl0 = (double)tl[0];
string tl1 = (string)tl[1];
int m = (int)tl[2]["month"], d = (int)tl[2]["day"];
int year = (int)tl[2]["year"];
FileNode tm = fs["mystruct"];
Rect r;
r.x = (int)tm["x"], r.y = (int)tm["y"];
r.width = (int)tm["width"], r.height = (int)tm["height"];
int lbp_val = 0;
FileNodeIterator it = tm["lbp"].begin();
for(int k = 0; k < 8; k++, ++it)
  lbp_val |= ((int)*it) << k;
  //*/

cvWaitKey(0);  

return 0;  
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
OpenCV学习笔记(六)
Opencv系列1.7--图像和视频
Yml文件的读取与写入(转)
【从零学习OpenCV】保存和读取XML和YMAL文件
OpenCV中CascadeClassifier类实现多尺度检测源码解析
OpenCV进阶之路:一个简化的视频摘要程序 - 博客 - 伯乐在线
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服