Matlab 2013 (64)+ VS 2013 + OpenCV 2.4.8
OS: Win 7 64
Reference: http://blog.csdn.net/raodotcong/article/details/8785358
Futher:
http://xanthippi.ceid.upatras.gr/people/evangelidis/matlab_opencv/data/matlab_to_opencv.pdf
1.添加环境变量
2.为Matlab关联VS
下载并按说明添加5个文件,否则matlab会找不到VS
http://download.csdn.net/download/hxldxl/6780589
3.创建 opencv2matlab.cpp
#include <iostream>
#include <string>
#include "opencv2/opencv.hpp"
#include "mex.h"
// Matlab entry point function
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] )
{
// Check if the input argument is legal
if ( nrhs != 1 || !mxIsChar( prhs[0] ) )
{
mexErrMsgTxt("An image name should be given.\n");
}
// Get the name of the image
int nStringLen;
nStringLen = mxGetNumberOfElements(prhs[0]);
std::string szImageName;
szImageName.resize( nStringLen + 1 );
mxGetString( prhs[0], &szImageName[0], nStringLen + 1 );
// Read the image from file
cv::Mat image;
image = cv::imread( szImageName );
// Show the image if it is successfully read from disk
if ( !image.empty() )
{
cv::imshow( "Test Mex OpenCV", image );
}
else
{
mexErrMsgTxt("The specified image does not exist.\n");
}
}
4.设置matlab路径为cpp,编译
mex opencv2matlab.cpp ...
-ID:\ProgramFiles\OpenCV\OpenCV-2.4.8\opencv\build\include ...
-LD:\ProgramFiles\OpenCV\OpenCV-2.4.8\opencv\build\x64\vc12\lib ...
-lopencv_contrib248 ...
-lopencv_core248 ...
-lopencv_features2d248 ...
-lopencv_flann248 ...
-lopencv_gpu248 ...
-lopencv_highgui248 ...
-lopencv_imgproc248 ...
-lopencv_legacy248 ...
-lopencv_ml248 ...
-lopencv_objdetect248 ...
-lopencv_ts248 ...
-lopencv_video248
4.调用