1

What is the best way to edit/update YAML/YML file in OpenCV ?

Rudi
  • 700
  • 1
  • 8
  • 19
  • 1
    Use a YAML library? I think yaml-cpp is pretty good. – Linuxios Jul 08 '12 at 23:53
  • 1
    How you process/read a YAML file is not related to OpenCV but your programming language. As you are using c++ I agree with @Linuxios about yaml-cpp – diip_thomas Jul 10 '12 at 08:52
  • 1
    @Linuxios and diip_thomas The advantage of OpenCV FileStorage is that you can use same code for XML as well as for YAML, hence I would like to stick with OpenCV if possible! – Rudi Jul 20 '12 at 21:09

2 Answers2

2

There is NO DIRECT support for update in YAML in general because it need to rewrite the whole file below the update node, so the reason in OpenCV as well as in yaml-cpp dont support direct edit of node value. So, the work around is re-create/write YAML structure again.

Rudi
  • 700
  • 1
  • 8
  • 19
0

It looks like OpenCV has some native ways to read and write YAML. From this SO answer, I found the following "cheat sheet" for the OpenCV C++ interface:

https://code.ros.org/trac/opencv/export/3163/trunk/opencv/doc/opencv_cheatsheet.pdf

A portion of their example to write YAML:

FileStorage fs("test.yml", FileStorage::WRITE);
fs << "i" << 5 << "r" << 3.1 << "str" << "ABCDEFGH";

If you're interested in updating an existing YAML file, it seems like the best way is to read the existing file into your own data type, make your changes, and then write the new data to the file.

Community
  • 1
  • 1
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
  • I am looking for edit i.e. updating the key value if they exist already but FileStorage::WRITE just add thing at the end of file :( – Rudi Jul 20 '12 at 21:04