OPENCV(3) —— 对XML和YAML文件实现I/O 操作
XML\YAML文件在OpenCV中的数据结构为FileStorage
string filename = "I.xml";
FileStorage fs(filename, FileStorage::WRITE);
\\...
fs.open(filename, FileStorage::READ);fs.release();
写入文件使用 << 运算符 ,读取文件,使用 >> 运算符
fs << "iterationNr" << 100;int itNr;
fs["iterationNr"] >> itNr;
itNr = (int) fs["iterationNr"];
OpenCV 数据结构的输入和输出
Mat R = Mat_<uchar >::eye (3, 3),
T = Mat_<double>::zeros(3, 1);
fs << "R" << R; // Write cv::Mat
fs << "T" << T;
fs["R"] >> R; // Read cv::Mat
fs["T"] >> T;
vector要注意在第一个元素前加上“[”,在最后一个元素前加上"]"
fs << "strings" << "["; // text - string sequence
fs << "image1.jpg" << "Awesomeness" << "baboon.jpg";
fs << "]"; // close sequence
对于map结构的操作使用的符号是"{"和"}"
fs << "Mapping"; // text - mapping
fs << "{" << "One" << 1;
fs << "Two" << 2 << "}";
读取这些结构的时候,会用到FileNode和FileNodeIterator数据结构。对FileStorage类的[]操作符会返回FileNode数据类型,对于一连串的node,可以使用FileNodeIterator结构
FileNode n = fs["strings"]; // Read string sequence - Get node
if (n.type() != FileNode::SEQ)
{
cerr << "strings is not a sequence! FAIL" << endl;
return 1;
}
FileNodeIterator it = n.begin(), it_end = n.end(); // Go through the node
for (; it != it_end; ++it)
cout << (string)*it << endl;
<?xml version="1.0"?>
<opencv_storage>
<depthImg190 type_id="opencv-image">
<width>320</width>
<height>240</height>
<origin>top-left</origin>
<layout>interleaved</layout>
<dt>w</dt>
<data>
0 0 0 0 27120 27384 27120 27120 27384 27120 27120 27120 27120 27384
27384 27664 27664 27944 27944 27664 27664 27944 27944 27944 28224
27944 27944 28224 28224 28224 28224 28520 28816 29120 29120 29120
29120 29120 29120 29120 29432 29744 30072 30072 29744 29744 30072
30072 30072 30400 30400 30736 30736 31080 31080 31080 31440 31440
31440 31440 31800 31800 31800 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 27120 27120 27120 27120 27384 27384 27384 27384 27384 27384
</depthImg190>
</opencv_storage>
这种格式不能直接使用xml,而需要
IplImage* depth=(IplImage*)cvLoad("depthImg190.xml");
cvLoad 函数
const char* filename = "zhang.jpg"; std::ifstream file(filename);
std::vector<char> data; file >> std::noskipws; // noskipws 不忽略空白
std::copy(std::istream_iterator<char>(file), std::istream_iterator<char>(), std::back_inserter(data)); cv::Mat matrixJprg = cv::imdecode(cv::Mat(data), 1);
IplImage qImg;
qImg = IplImage(matrixJprg); // cv::Mat -> IplImage 可以直接强制转换 cvSaveImage("./out.jpg", &qImg);cvSaveImage 直接把 cv::Mat 数据保存为图片会出现问题,需要以上的代码强制转换
OPENCV(3) —— 对XML和YAML文件实现I/O 操作的更多相关文章
- 对XML和YAML文件实现I/O操作
1.文件的打开关闭 XML\YAML文件在OpenCV中的数据结构为FileStorage,打开操作例如: string filename = "I.xml"; FileStora ...
- opencv 3 core组件进阶(3 离散傅里叶变换;输入输出XML和YAML文件)
离散傅里叶变换 #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" ...
- OpenCV之XML和YAML文件读写
FileStorage类 该类有两个构造函数 FileStorage::FileStorage() FileStorage::FileStorage(const string& source, ...
- OpenCV——输入输出XML和YAML文件
- OpenCV 输入输出XML和YAML文件
#include <opencv2/core/core.hpp> #include <iostream> #include <string> using names ...
- OpenCV教程(42) xml/yaml文件的读写
参考资料: http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html #include "opencv2/openc ...
- <学习opencv>图像、视频和数据文件
/*=========================================================================*/ // openCV中的函数 /*====== ...
- Python 第五篇(下):系统标准模块(shutil、logging、shelve、configparser、subprocess、xml、yaml、自定义模块)
目录: shutil logging模块 shelve configparser subprocess xml处理 yaml处理 自定义模块 一,系统标准模块: 1.shutil:是一种高层次的文件操 ...
- 持续集成时 travis 和 codecov 等 yaml 文件的配置
最近在项目中在配置CodeCov 以及Travis 和 AppVeyor做持续集成时,遇到了一些问题,也解决了一些问题.顺便拿来分享一下. 首先时Travis,这个主要是来跑基于 Linux 环境下的 ...
随机推荐
- GenIcam标准(四)
2.8.可用的节点类型 本章对每个可用的节点类型提供一个概要的描述,包括其功能.用途以及最关心的参数.另外,对于每个节点在GenICam标准的XML格式文件中的layout,会有一个正式的说明.这个格 ...
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
- HDU 4756 Install Air Conditioning(次小生成树)
题目大意:给你n个点然后让你求出去掉一条边之后所形成的最小生成树. 比較基础的次小生成树吧. ..先prime一遍求出最小生成树.在dfs求出次小生成树. Install Air Conditioni ...
- [Javascript] Simplify Creating Immutable Data Trees With Immer
Immer is a tiny library that makes it possible to work with immutable data in JavaScript in a much m ...
- SVN配置以及自己主动部署到apache虚拟文件夹
SVN配置以及自己主动部署到apache虚拟文件夹 一.VisualSVN server 服务端和TortoiseSVNclient下载 VisualSVN下载:http://subversion.a ...
- 4、java变量、函数、基本类型的值传递、分支、循环、流程控制
一.全局变量(global).局部变量(local).动态变量(dynamic).静态变量(static) 在类中的变量为全局变量,在方法函数中为局部变量,局部变量必须有人为赋的初值,全局变量的初值是 ...
- 49.AngularJs 指令directive之controller,link,compile
转自:https://www.cnblogs.com/best/tag/Angular/ 关于自定义指令的命名,你可以随便怎么起名字都行,官方是推荐用[命名空间-指令名称]这样的方式,像ng-cont ...
- Session原理、安全以及最基本的Express和Redis实现
Session原理.安全以及最基本的Express和Redis实现 https://segmentfault.com/a/1190000002630691
- Dictionaries and lists
Lists can appear as values in a dictionary. For example, if you were given a dictionary that maps fr ...
- PGA和UGA内存的使用情况
引用thomas kyte的PGA和UGA的统计内存的使用情况,用排序区不同的大小来查看pga.UGA.物理读取不同内存使用 会话1:创建测试表和测试不同排序大小 create table t as ...