sdarella
sdarella

Reputation: 39

Mat to XML in C# Emgu

I wish to save the calibration parameters of my cameras in XML files using EMGU OpenCV. The parameters are in Mat data type, so I'm trying to convert Mat to XML.

I keep getting a reflecting type exception: "you must implement a default accessor on System.Array because it inherits from ICollection". Would anyone know how to fix this issue?

        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();

I have also tried

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

But it gives an error message saying that "saving to XML is not supported". Using Imwrite instead also gave an error message ("could not find a writer for the specific extension").

EMGU wiki says to use cvSave, however I could not find such method. In fact, cvSave is nowhere to be found in the documentation (http://www.emgu.com/wiki/files/3.1.0)

Upvotes: 2

Views: 1587

Answers (1)

sdarella
sdarella

Reputation: 39

For anyone that find themselves with the same problem, I have found a way of saving the camera matrices that does not use any of the above methods.

I simply instantiate an object of the FileStorage class from Emgu.CV (http://emgu.com/wiki/files/3.1.0/document/html/c0942d4b-fcd7-38b9-a1c8-1ac9413e53eb.htm). "filePath" contains the full directory address and fileName.xml

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

I am not sure if this is the best way, but it did create the .xml file and wrote the mat matrixData to the file.

Upvotes: 2

Related Questions