Ask Your Question

Best way to save cv::Mat and load it in Matlab?

asked 2013-03-25 01:05:36 -0500

mrgloom gravatar image

Best way to save something in cv::Mat(or other opencv format) and then load it in Matlab?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-29 13:38:20 -0500

updated 2013-03-29 13:39:41 -0500

I am using three ways to interface Matlab and OpenCV:

  1. save image using cv::imwrite (load in Matlab by imread), this obvious method can be applied only for UINT8 and FLOAT images, however if the image holds UINT32 or NaN there are problems.
  2. save the image into *.txt file (using some custom function) and load it using 'dlmread' function into Matlab. Any values can be saved this way, even NaN, which is sometimes useful. OpenCV also supports saving into XML format, but I found it overkill for storing simple numerical arrays.
  3. use of MEX files in Matlab to access directly the image data in C/C++. This goes only in direction from Matlab->C/C++ and requires writing and building MEX functions for specific purposes.

I am not satisfied with these approaches myself, but hopefully it gives some ideas. What I need all the time is to access local variables during debugging OpenCV application. Visual Studio allows using 'Immediate Window' to inspect variables. Ideally, I would like to access the local variables in Matlab and work with them.

Assuming I know the pointer to the beginning of image data during debugging OpenCV, it would be great to read from this location the data to Matlab. Is that possible?

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-03-25 01:05:36 -0500

Seen: 3,153 times

Last updated: Mar 29 '13