在 C# Emgu 中垫到 XML

Mat to XML in C# Emgu

我希望使用 EMGU OpenCV 将相机的校准参数保存在 XML 文件中。参数是 Mat 数据类型,所以我试图将 Mat 转换为 XML.

我不断收到反射类型异常:"you must implement a default accessor on System.Array because it inherits from ICollection"。有人知道如何解决这个问题吗?

        XmlSerializer serializer = new XmlSerializer(typeof(Mat));
        Stream fs = new FileStream(path, FileMode.Create);
        XmlWriter writer = new XmlTextWriter(fs, Encoding.Unicode);
        serializer.Serialize(writer, XMLData);
        writer.Flush();

我也试过了

 XMLData.Save(path+"calib.xml");

但它给出了一条错误消息,指出 "saving to XML is not supported"。使用 Imwrite 而不是也给出了错误消息 ("could not find a writer for the specific extension")。

EMGU wiki 说要使用 cvSave,但是我找不到这样的方法。事实上,在文档中找不到 cvSave (http://www.emgu.com/wiki/files/3.1.0)

对于遇到同样问题的任何人,我找到了一种不使用上述任何方法的保存相机矩阵的方法。

我只是从 Emgu.CV (http://emgu.com/wiki/files/3.1.0/document/html/c0942d4b-fcd7-38b9-a1c8-1ac9413e53eb.htm) 实例化了一个 FileStorage class 的对象。 "filePath" 包含完整的目录地址和 fileName.xml

fs = new FileStorage(filePath, FileStorage.Mode.Write);
fs.Write(matrixData);

我不确定这是否是最好的方法,但它确实创建了 .xml 文件并将 mat matrixData 写入文件。