What is the best way to edit/update YAML/YML file in OpenCV ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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.