Matlab 2013 (64)+ VS 2013 + OpenCV 2.4.8



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

WritingMATLABC-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 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.調用


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章