典型的.yml或.xml矩阵应如何使用OpenCV [英] How should a typical .yml or .xml matrix look for OpenCV use

查看:95
本文介绍了典型的.yml或.xml矩阵应如何使用OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文件内指定一个矩阵,然后将其作为Mat加载到OpenCV上以进行进一步处理.如何指定cols和lines以及 .xml .yml 文件中的元素在哪里?(例如,i的元素A(i,j)从1到m行和j从1到n cols. 例如,在Matlab中,这是通过仅加载数字的 .dat 文件来完成的.与OpenCV混淆的是 .yml .xml 还有其他一些脚本.

I need to specify a matrix inside a file and then load it onto OpenCV as a Mat for further processing. How can the cols and lines be specified and where do elements go within the .xml or .yml file?, (for example element A(i,j) for i from 1 to m lines and for j from 1 to n cols. In Matlab for example, this is done by loading a .dat file with just the numbers. What is confusing with OpenCV is that the .yml or .xml have some other scripts to them.

推荐答案

.xml / .yaml 文件中读取/写入任何OpenCV数据结构非常简单

Read/Write any OpenCV data structure to or from .xml / .yaml file is very simple.

在将任何内容写入此类文件之前,需要先将其打开,然后最后将其关闭. OpenCV中的XML/YAML数据结构为FileStorage.

Before you write any content to such file you need to open it and at the end to close it. The XML/YAML data structure in OpenCV is FileStorage.

string filename = "I.xml";
FileStorage fs(filename, FileStorage::WRITE);

Mat R = Mat_<uchar >::eye (3, 3),

fs << "R" << R; // Write entire cv::Mat
fs["R"] >> R;   // Read entire cv::Mat

查看此链接使用XML和YAML文件的文件输入和输出

这篇关于典型的.yml或.xml矩阵应如何使用OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆