Mixed with Matlab and C ++ for the first time, combined with some online tutorials, and finally realized the function. Although the understanding is not very deep, it is recorded first, and then slowly understand.
- Enter the command “Mex -Setup C ++” in the MATLAB command line window. At this time, it is shown in the figure below:
- Enter the command “Mbulid -Setup C ++” in the Matlab command line window. At this time, it is shown in the figure below:
- At this time, the compilation environment is done, but you must write a test code before modifying through the configuration of the file XML.
#include"mex.h" #include <opencv/cv.h> #include <opencv2/highgui/highgui.hpp> #pragma comment( lib, "opencv_world310.lib") void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char name[256]; int buflens =mxGetNumberOfElements(prhs[0]); mxGetString(prhs[0], name, buflens+1); if(!mxIsChar(prhs[0])) { mexErrMsgTxt("First parameter must be string/n"); return ; } mexPrintf(name); IplImage * img = cvLoadImage(name); if(img->imageData == NULL) { mexErrMsgTxt("Error in image/n"); return; } cvNamedWindow("test"); cvShowImage("test",img); cvWaitKey(0); return; }
Then enter the command “MEX -V Opencvtest.cpp” to find the need to rewrite the XML file, as shown in the figure below:
Use VS2010 to open, pull directly to the bottom, and modify the code as follows: (“Other configuration attributes” are open as soon as it is opened, and the latter is added.
<ENV
PATH = "Other configuration attributes; d: \ opencv3.1.0 \ opencv \ build \ x64 \ vc12 \ bin;"
Include = "Other configuration attributes; d: \ opencv3.1.0 \ opencv \ Build \ Include;
D: \ opencv3.1.0 \ opencv \ build \ influde \ opencv;
D: \ opencv3.1.0 \ opencv \ build \ influde \ opencv2; "
Lib = "Other configuration attributes; d: \ opencv3.1.0 \ opencv \ build \ x64 \ vc12 \ lib \;"
Libpath = "Other configuration attributes; d: \ opencv3.1.0 \ opencv \ build \ x64 \ vc12 \ lib \;"
/>
</config>
At this time, enter the command “Mex -Largearraydims Opencvtest.cpp” to compile, and as shown in the figure, it is successful:
Note: The compilation pass does not mean that it can run. When many people (including me) are running, they will appear
The reason for this situation is that the DLL file that the MEXW64 file relies on (I don’t know why I can’t find it). The solution is to put OpenCV_WORLD310.dll and the program on a folder (I don’t know there is still there any more There are no other effective ways), and the final operation is finally successful,