Ask Your Question

Revision history [back]

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?

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?