【问题标题】:Emgucv How to convert FileNode to Matrix?Emgucv 如何将 FileNode 转换为 Matrix?
【发布时间】:2016-03-16 07:12:42
【问题描述】:
<CM1 type_id="opencv-matrix">
  <rows>3</rows>
  <cols>3</cols>
  <dt>d</dt>
  <data>
    5.1385274254160595e+002 0. 3.2910027190134770e+002 0.
    5.1238136591053387e+002 2.5289438862525913e+002 0. 0. 1.</data></CM1>

我有一个包含矩阵的 xml 文件。

在 c++ 中,我们可以这样使用:

FileStorage fs("camera parameters.xml", FileStorage::READ);
Mat CM1;
fs["CM1"] >> CM1;

获取矩阵对象。

如何在 C# 中做到这一点?

FileStorage fs = new FileStorage("camera parameters.xml", FileStorage.Mode.Read);
Mat CM1;
CM1 = new Mat(fs["CM1"]); //doesn't work, stuck here

【问题讨论】:

    标签: c# c++ emgucv


    【解决方案1】:

    要使用FileStorage 对象从xml 文件中读取Mat 对象,您可以使用FileNode.ReadMat() 方法。

    Mat CM1 = new Mat();    
    FileStorage fs = new FileStorage("camera parameters.xml", FileStorage.Mode.Read);
    if (fs.IsOpened)
    {
       fs.GetNode("CM1").ReadMat(CM1);
    }
    

    确保首先调用new Mat() 来实例化 Mat 对象,以避免内存访问冲突异常。

    【讨论】:

      猜你喜欢
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多