且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何写一个Float Mat到OpenCV中的文件

更新时间:2023-01-08 10:12:28

使用纯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

获取数据:


  1. 使用任何编辑器打开文件

  2. 然后压缩除数据标签内容之外的所有文本和数字)。

  3. 完成后,使用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.