Pregunta

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

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top