我一般会在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/