如何保存和读取 XML 新的 C++ OpenCV 中的样式矩阵对象?
旧的 C 风格 cvMat 矩阵可以传递给 cvSave() 函数,以便轻松写入 XML 文件。此函数不接受新的 C++ 样式 cv::Mat
和 cv::Mat_
矩阵。
OpenCV 参考中有一个关于 XML 持久性的部分,但是这三个类(FileStorage、FileNode 和 FileNodeIterator)缺乏任何描述或示例,我无法弄清楚如何从界面使用它们。
谢谢。
编辑:这实际上涉及OpenCV的新C++界面中的许多其他功能,从版本2.1开始。文档在某些地方非常糟糕,函数参数不一致,用户组要么不知道,要么有比回答问题更好的事情要做。我将坚持使用旧的 C 界面一段时间。这些文档好多了,更不用说 O'Reilly 的书了。
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.
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.
Thanks.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,C++ 风格更容易,但正如您所说,没有任何容易获得的文档。
要在文件中写入
cv::Mat
,只需创建一个FileStorage
变量,然后按照您使用cout
在屏幕上打印的样式写入矩阵。阅读方式也与cin风格类似,但最好看一下下面的链接以便更好地理解。在数据 I/O 部分的第二页上,他们展示了如何使用 XML/YAML 的示例。
opencv C++ 备忘单(与文档 PDF 中的备忘单不同) )
Apparently its easier in C++ style, but as you said there aren't any easily available documentation.
To Write
cv::Mat
in a file just create aFileStorage
variable and then write the matrix in the style you usecout
to print on screen.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++ cheatsheet(different than cheatsheet in the documentation PDF)
上面是正确的,但是备忘单没有显示您需要打开该文件。这似乎是显而易见的,但我忽略了这样做,因为备忘单没有说我必须这样做。这是允许您正确写入文件的代码
---------- 代码:
没关系,这仍然不起作用。抱歉浪费了帖子。
The above is correct, but what the cheatsheet does not show is that you need to open the file. This may seem obvious, but I neglected to do it because the cheatsheet didn't say I had to. here is the code that will allow you to write to the files correctly
---------- code:
Nevermind, this still doesn't work. sorry for the wasted post.