c++ - 如何在 OpenCV 中以编程方式在 YAML 中编写注释?

标签 c++ opencv comments yaml

我一般会在YAML中加入注释,方便读者快速理解YAML参数。

%CommentC: "~~~~~~~~~~~~~~~~~~~Filtering Setting~~~~~~~~~~~~~~~~~~~"
WindowSize: 3
Sigma: 3
LowerThreshold: 25
HigherThreshold: 35 

但是如何使用 FileStorage 在 OpenCV 中以编程方式编写评论?

最佳答案

你可以使用函数:

/* writes a comment */
CVAPI(void) cvWriteComment( CvFileStorage* fs, const char* comment, int eol_comment );

这是工作示例:

#include <opencv2\opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    {
        FileStorage fs("test.yml", FileStorage::WRITE);

        cvWriteComment(*fs, "a double value", 0);
        fs << "dbl" << 2.0;

        cvWriteComment(*fs, "a\nvery\nimportant\nstring", 0);
        fs << "str" << "Multiline comments work, too!";
    }

    {
        double d;
        string s;
        FileStorage fs("test.yml", FileStorage::READ);
        fs["dbl"] >> d;
        fs["str"] >> s;
    }

    return 0;
}

test.yml 文件:

%YAML:1.0
# a double value
dbl: 2.
# a
# very
# important
# string
str: "Multiline comments work, too!"

关于c++ - 如何在 OpenCV 中以编程方式在 YAML 中编写注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32471795/

相关文章:

eclipse - 如何在 Eclipse RCP 中自动为我们编写的方法生成注释?

c++ - B树递归搜索C++

java - 如何将opencv Mat坐标转换为android中的布局坐标?

c++ - 使用模板实现双端队列的问题

image - plt.imshow 在 IPython 中显示灰度图像的彩色图像

python - 使用OpenCV自动调整图像的亮度

facebook - 如何审核来自社交插件 facebook 的评论?

html - 在正确的位置减少 CSS 注释

c++ - 如何将 "extern template"与由同一类中的模板化成员使用的嵌套类一起使用?

c++ - DLL和绘图功能消失