如何在OpenCV中保存和读取XML中的新C ++样式矩阵对象? [英] How can I save and read from XML the new C++ style matrix objects in OpenCV?

查看:313
本文介绍了如何在OpenCV中保存和读取XML中的新C ++样式矩阵对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以将旧的C风格的cvMat矩阵传递给cvSave()函数,以方便地将其写入XML文件.此函数不接受新的C ++样式cv::Matcv::Mat_矩阵.

The old, C style cvMat matrices could be passed to the cvSave() function for easy writing to an XML file. The new C++ style cv::Mat and cv::Mat_ matrices are not accepted by this function.

OpenCV参考中有关于XML持久性的部分,但是三个类(FileStorage,FileNode和FileNodeIterator)缺少任何描述或示例,我无法从接口中弄清楚如何使用它们.

The OpenCV reference has a section on XML persistence, but the three classes (FileStorage, FileNode and FileNodeIterator) lack any description or example and I can't figure out how to use them from the interface.

谢谢.

编辑:实际上,这与 2.1版本的 OpenCV 的新 C ++ 界面中的许多其他功能有关,.该文档的位置非常贫乏,函数参数不一致,并且用户组不知道,或者比回答问题还有更好的事情要做.我将使用旧的 C 界面一段时间.文档好多了,更不用说O'Reilly的书了.

EDIT: This actually concerns a lot of other functionality in the new C++ interface of OpenCV, as of Version 2.1. The documentation is very poor in places, the function arguments are inconsistent, and the user group either has no idea, or has better things to do than answer questions. I'm going to stick to the old C interface for a while. The docs are tons better, not to mention the book by O'Reilly.

推荐答案

在C ++风格中,它显然更容易,但是正如您所说的那样,没有任何容易获得的文档.

Apparently its easier in C++ style, but as you said there aren't any easily available documentation.

要在文件中写入cv::Mat,只需创建一个FileStorage变量,然后以您使用cout在屏幕上打印的样式编写矩阵.

To Write cv::Mat in a file just create a FileStorage variable and then write the matrix in the style you use cout to print on screen.

cv::Mat someMatrix;
//you create and assign values to someMatrix however you plan to.
FileStorage fs("myFile.yml", FileStorage::WRITE);
fs << "name_to_identify_matrix_by" << someMatrix;

阅读也类似于cin风格,但是阅读下面的链接可以更好地理解它,这更好.在数据I/O"部分的第二页上,他们显示了有关如何使用XML/YAML的示例.

Reading is also similar to cin style, but its better you take a look at the below link to have a better understanding. On 2nd page in section Data I/O they have shown examples on how to use XML/YAML.

opencv C ++速查表(与文档PDF)

这篇关于如何在OpenCV中保存和读取XML中的新C ++样式矩阵对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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