<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
若要使用 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);
}
请确保通过首先调用 Mat 来实例化 Mat 对象new Mat()
以避免内存访问冲突异常。