[英]Emgucv How to convert FileNode to Matrix?
<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>
I have an xml file that contains a matrix. 我有一个包含矩阵的xml文件。
In c++, we can use this: 在c ++中,我们可以使用以下代码:
FileStorage fs("camera parameters.xml", FileStorage::READ);
Mat CM1;
fs["CM1"] >> CM1;
to get the matrix object. 获取矩阵对象。
How can I do this in C#? 我怎么能在C#中做到这一点?
FileStorage fs = new FileStorage("camera parameters.xml", FileStorage.Mode.Read);
Mat CM1;
CM1 = new Mat(fs["CM1"]); //doesn't work, stuck here
To read a Mat
object from an xml file using a FileStorage
object, you can use the FileNode.ReadMat()
method. 要使用
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);
}
Make sure you instantiate the Mat object by calling new Mat()
first to avoid a memory access violation exception. 确保首先通过调用
new Mat()
来实例化Mat对象,以避免内存访问冲突异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.