如何写一个Float Mat到OpenCV中的文件 [英] How to write a Float Mat to a file in OpenCV
问题描述
我有一个矩阵
Mat B(480,640,CV_32FC1);
包含浮动值...我想将这个矩阵写入一个文件,可以在记事本或Ms字或Excel中打开查看内部的值和存储.... 编写功能只能保存8位或16位图片。
containing floating values..I want to write this matrix to a file which could be opened in notepad or Ms word or Excel to see the values inside and for storage....imwrite function can save 8-bit or 16-bit image only..
如果这样做可以删除您的建议?如果是,
Drop in your suggestions if this could be done?? if yes, how ??
推荐答案
使用纯OpenCV API调用:
Using pure OpenCV API calls:
// Declare what you need
cv::FileStorage file("some_name.ext", cv::FileStorage::WRITE);
cv::Mat someMatrixOfAnyType;
// Write to file!
file << someMatrixOfAnyType;
文件扩展名可以是 xml 或 yml 。
在这两种情况下,你会得到一个小的头,你可以轻松地删除/解析,然后你可以访问浮点格式的数据。
我使用这个方法成功(使用yml文件)获取数据到Matlab和Matplotlib
The file extension can be xml or yml. In both cases you get a small header that you can easily remove/parse, then you have access to the data in a floating point format. I used this approach successfully (with yml files) to get data into Matlab and Matplotlib
获取数据:
- 使用任何编辑器打开文件
- 然后压缩除数据标签内容之外的所有文本和数字)。
- 完成后,使用txt或csv扩展名保存文件,然后使用matlab(拖放工程)打开。
Voilà。如果没有正确猜测图像大小,可能需要在matlab命令行中重新生成矩阵。
Voilà. You may have to reshape the resulting matrix in matlab command line if it didn't guess correctly the image size.
这篇关于如何写一个Float Mat到OpenCV中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!