Matlab 2013 (64)+ VS 2013 + OpenCV 2.4.8

来源:互联网 发布:报了java培训班学不会 编辑:程序博客网 时间:2024/04/30 01:21


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

WritingMATLAB C-MEX Code

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 functionvoid 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.调用


0 0
原创粉丝点击