Emgucv如何将FileNode转换为Matrix?

时间:2016-03-16 07:12:42

标签: c# c++ emgucv

<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

1 个答案:

答案 0 :(得分:0)

要使用Mat对象从xml文件中读取FileStorage对象,可以使用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对象,以避免内存访问冲突异常。