Parsing XML or YML in OpenCV with Python

With openCV, you can save / load data in YML or XML format. It is easy using cv::FileStorage using the C ++ API. I cannot get it to work with the python API.

Here is an example of a YML file created using the opencv C ++ API.

If someone manages to download it using the openCV python API, let me know!

+4
source share
1 answer

I was late to the party, but I did not find a way to do this in pure Python, as the YAML files created by OpenCV (YAML 1.0) are not fully compatible, and are not easily readable with the YAML libraries available in Python (YAML 1.1).

Python / OpenCV links exist, but this is just a bunch of C methods with absolutely no documentation, so at the moment they are almost unusable.

However, writing a small C extension and wrapping it in a class was pretty easy to do, so I suggest you try it. If you (or anyone else) still need it, I may be able to release the code for the small module that I wrote, I will ask for it to 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) 
+4
source

All Articles