C2Mat
C2Mat is a simple wrapper library that allows OpenCV data structures to be transferred between C++ and Matlab. It lets a program to combine the speed of OpenCV with the power of Matlab.
Your program and a Matlab window will run in separate threads. Using a COM interface, Matlab allows external programs (such as C2Mat) to access it. Using C2Mat to send text commands from your program will have the same effect as typing them in to the Matlab window. If you want to transfer data between your program and Matlab, calling the appropriate C2Mat command will allow you to copy the data (such as an IplImage) between your program's memory space and the Matlab workspace.
Some examples:
--------------------------------
for(Sint32 i=0;i<10;i++)
numbers[i]=i;
//Send numbers to Matlab and square them
engine->putSint16(numbers,10,"numbers");
engine->evalString("numbers2=numbers.^2;");
//Retrieve the numbers from Matlab
Sint32 *numbers2=engine->getSint32("numbers2");
--------------------------------
--------------------------------
//Send an IplImage to Matlab
engine->putIplImage(im,"im");
//Blur it
engine->evalString("blurredIm=imfilter(im,fspecial('average', 15));");
//Return the result
engine->getIplImage(blurredIm,"blurredIm");
--------------------------------
Other examples are included in the .zip file. The main project homepage for C2Mat is http://sourceforge.net/projects/c2mat/.
Another related program you might want to check out is "C/C++ and Matlab types convertor", available from Matlab Central.
Cite As
Peter Barnum (2024). C2Mat (https://www.mathworks.com/matlabcentral/fileexchange/25009-c2mat), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Image Processing and Computer Vision > Computer Vision Toolbox > Code Generation, GPU, and Third-Party Support >
- MATLAB > External Language Interfaces > C++ with MATLAB > Call C++ from MATLAB >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.