4

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.`

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

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

1

1 Answer 1

4

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).

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.

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)
6
  • Thx. Code module would be great! What wrapper did you use ?
    – Eric
    May 9, 2013 at 11:20
  • Just plain C methods and a small Python class that makes them more useable. It's easier than using CTypes/Cython/whatever else as most OpenCV code samples are... in C++.
    – F.X.
    May 9, 2013 at 21:17
  • Can you please post the source for the extension and wrapper?
    – mpenkov
    May 30, 2013 at 10:01
  • I meant to ask but totally forgot about this. Added to my todo list this time, I'll send the module next week when I can if they are okay ;)
    – F.X.
    May 30, 2013 at 20:53
  • @F.X. Any module available for testing ? :)
    – Eric
    Nov 20, 2013 at 10:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.