Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在OpenCV中以编程方式在YAML中编写注释?_C++_Opencv_Comments_Yaml - Fatal编程技术网

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

C++ 如何在OpenCV中以编程方式在YAML中编写注释?,c++,opencv,comments,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) cvWri

我通常在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 );
void cv::FileStorage::writeComment(const String &   comment, bool  append = false)  
这是一个工作示例:

#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;
}

在新版本的OpenCV(3.2或更高版本)中,我们使用
FileStorage
编写注释的方式与以前的版本略有不同。这就是功能:

/* writes a comment */
CVAPI(void) cvWriteComment( CvFileStorage* fs, const char* comment, int eol_comment );
void cv::FileStorage::writeComment(const String &   comment, bool  append = false)  
例如:

#include <opencv2/core.hpp>
#include <iostream>
#include <string>

using namespace cv;
using namespace std;

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

        fs.writeComment("a double value", 0);
        fs << "dbl" << 2.0;

        fs.writeComment("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;
}

现在如何编写YAML文件?手动(使用例如
std::ostream
和输出操作符
我使用cv::FileStorage,因此您在执行类似
someFileStorage的操作时,它会返回一个错误。这就是我问这个问题的原因。可能有一些官方方法可以编写YAML注释。您可以编辑您的问题以包含错误(完整和未编辑的)吗,以及导致错误的代码?非常感谢!祝您愉快!抱歉,我忘了!:)此功能是否仍存在于
OpenCV-3.0
中?