读书人

Win7上Matlab中使用Visual Studio 201

发布时间: 2012-08-08 14:32:45 作者: rapoo

Win7下Matlab中使用Visual Studio 2010编译Opencv的Mex文件

编译命令:

mex testmex.cpp -I"C:\opencv24\opencv\build\include" -I"C:\opencv24\opencv\build\include\opencv" -L"C:\opencv24\opencv\build\x64\vc10\lib" -lopencv_core241 -lopencv_highgui241 -lopencv_imgproc241

这里关键是正确指定库文件查找路径

testmex.cpp内容

//file: testmex.cpp//编译命令:mex testmex.cpp -I"C:\opencv24\opencv\build\include" -I"C:\opencv24\opencv\build\include\opencv" -L"C:\opencv24\opencv\build\x64\vc10\lib" -lopencv_core241 -lopencv_highgui241 -lopencv_imgproc241#include <iostream>#include "mex.h"#include "opencv2/opencv.hpp"using namespace std;using namespace cv;void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){    try    {        mexPrintf("come1\n");              Mat src = cv::imread("d:\\bird.jpg", CV_LOAD_IMAGE_GRAYSCALE), dst;               threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);                imshow("Source", src);        cv::imshow("Result", dst);        cv::waitKey(0);        cvDestroyAllWindows();        mexPrintf("over\n");    }    catch(const cv::Exception& ex)    {        char err[512];        sprintf(err, "Error:%s", ex.what());        mexPrintf(err);    }    mexPrintf("ok");}


读书人网 >编程

热点推荐