Skip to content
shimat edited this page Jan 19, 2019 · 1 revision

Write

using (var fs = new FileStorage("foo.yml", FileStorage.Mode.Write | FileStorage.Mode.FormatYaml))
{
    fs.Write("iii", 123);
    fs.Write("ddd", Math.PI);
    using (var tempMat = new Mat("lenna.png"))
    {
        fs.Write("mat", tempMat);
    }
}

foo.yml

%YAML:1.0
iii: 123
ddd: 3.1415926535897931e+000
mat: !!opencv-matrix
   rows: 512
   cols: 512
   dt: "3u"
   data: [ 125, 137, 226, 125, 137, 226, 133, 137, 223, 128, 136, 223,
       120, 138, 226, 116, 129, 226, 123, 138, 228, 124, 134, 227, 127, 
       ...

Read

using (var fs = new FileStorage("foo.yml", FileStorage.Mode.Read))
{
    int intValue = fs["iii"].ReadInt();
    double doubleValue = fs["ddd"].ReadDouble();
    // casting operators are also supported
    intValue = (int)fs["iii"];
    doubleValue = (double)fs["ddd"];

    Mat mat = fs["mat"].ReadMat();
    using (var window = new Window(mat))
    {
        Cv2.WaitKey();
    }
}