使用Python在OpenCV中进行XML或YML解析 [英] XML or YML parsing in OpenCV with Python

查看:1276
本文介绍了使用Python在OpenCV中进行XML或YML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用openCV,您可以使用YML或XML格式保存/加载数据。使用c ++ API很容易使用 cv :: FileStorage 。我无法使用python API。

With openCV you can save/load data with YML or XML format. It is easy with cv::FileStorage using c++ API. I cannot make it work with python API.`

这里是使用opencv c ++ API创建的YML文件的示例。

Here is an example of an YML file created using opencv c++ API.

如果有人成功加载openCV python API,请告诉我们!

If someone succeed to load it with openCV python API, let me know !

推荐答案

我晚了派对,但我没有找到任何办法做纯Python,因为由OpenCV(YAML 1.0)创建的YAML文件不是完全兼容,也不容易阅读与YAML库可以在Python(YAML 1.1)。

I'm late to the party, but I didn't find any way to do it in pure Python, as the YAML files created by OpenCV (YAML 1.0) aren't wholly compatible, nor easily read with the YAML libraries available in Python (YAML 1.1).

Python / OpenCV绑定存在,但只是一堆C方法,绝对没有文档,这是非常不可用的。

The Python/OpenCV bindings exist, but are just a bunch of C methods with absolutely no documentation, so they're pretty much unusable at this point.

然而,编写一个小的C扩展并将它包装在一个类很容易做,所以我建议你试试。如果你(或任何其他人)仍然需要它,我可以能够释放我写的小模块的代码,我会问在星期五的工作。

However, writing a small C extension and wrapping it in a class was pretty easy to do, so I suggest you try it out. In case you (or anybody else) still need it, I may be able to release the code of the small module I wrote that, I'll ask that at work on Friday.

为了给你一些想法,这里是我如何使用我的模块:

To give you some ideas, here is how I use my module :

with FileStorage("my/file.yml") as fs:
  print(fs["string"])  # Prints the "string" string key
  print(fs["int"])     # Prints the "int" integer key
  print(fs["matrix"])  # Prints a matrix (read as a NumPy array)

这篇关于使用Python在OpenCV中进行XML或YML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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