How can I convert an OpenCV layout that was written to an XML file back to an image?
I wrote some code to create an XML file that contains RGB data from a Mat file in OpenCV. I would like to recreate this image in MATLAB from data points in an XML file. However, I am not sure about the formatting of the xml file as when I open it it looks something like this:
<?xml version="1.0?>
<opencv_storage>
<myMatrix type_id="opencv-matrix">
<rows>116</rows>
<cols>116</cols>
<dt>u</dt>
<data>
97 101 97 98 99 97 ...
</data>
</myMatrix>
</opencv_storage>
+3
source to share
2 answers
you can convert it to matlab format in opencv.
read it when using Filestorage:
Mat m;
Filestorage fs("m.xml", Filestorage::READ);
fs["myMatrix"] >> m;
then print it (or write to file) in Matlab format:
// 2.4 version
cerr << format(m,"MATLAB") << endl;
// 3.0 version
cerr << format(m,cv::Formatter::FMT_MATLAB) << endl;
+3
source to share
Get the xml to struct conversion like this:
http://www.mathworks.com/matlabcentral/fileexchange/28518-xml2struct
this will allow you to convert the data to a structure, and then you can simply change your data:
pic = reshape(struct.data, struct.rows, struct.cols)
image(pic)
Note. It's not out of the box code.
0
source to share