如何将已经写入xml文件的OpenCV Mat转换回图像? [英] How to convert an OpenCV Mat that has been written in an xml file back into an image?
本文介绍了如何将已经写入xml文件的OpenCV Mat转换回图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一些代码来生成一个.xml文件,其中包含来自OpenCV中Mat文件的RGB数据。我想在MATLAB中从xml文件中的数据点重新创建此图像。我不知道xml文件的格式,因为当我打开它看起来像这样:
<? 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>
使用Filestorage读取它:
Mat m;
Filestorage fs(m.xml,Filestorage :: READ);
fs [myMatrix]> m;
然后以matlab格式输出(或写入文件):
// 2.4版本
cerr<<< format(m,MATLAB)<< endl;
// 3.0版本
cerr<<< format(m,cv :: Formatter :: FMT_MATLAB)< endl
I wrote some code to generate an .xml file that contains the RGB data from a Mat file in OpenCV. I would like to recreate this image in MATLAB from the data points in the xml file. I am however unsure of the formatting of the xml file, since 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>
解决方案
you can convert it to matlab format within opencv.
read it in using the Filestorage:
Mat m;
Filestorage fs("m.xml", Filestorage::READ);
fs["myMatrix"] >> m;
then print it out (or write to a file) in matlab format:
// 2.4 version
cerr << format(m,"MATLAB") << endl;
// 3.0 version
cerr << format(m,cv::Formatter::FMT_MATLAB) << endl;
这篇关于如何将已经写入xml文件的OpenCV Mat转换回图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文