The original address peak back to the jade turn
Recently in the Exercise Medicine Software optimization work, this software framework and algorithm language is fully implemented by MATLAB, although the MATLAB matrix operations, numerical computing ability is powerful, but the speed is unbearable. Software immediately ported to C + + is not practical, so the use of joint programming, the speed of an intolerable algorithm to C + + implementation, C + + in the implementation of code in the process of some numerical calculation and image processing algorithm OPENCV library functions.
There are many ways to write the MEX function call OpenCV Library on the internet, but none of them can be taken directly. After a step-by-step test, modification, and final completion, the process and contents are recorded and left to Yimeimei for reference.
The first step: (Refer to reference 1, but it is not written in detail, for beginners difficult to understand) to achieve MATLAB, C + +, OPENCV mixed programming compiler configuration and the automatic configuration of the link library. The method of reference 2, though feasible, is cumbersome to manually reconfigure each time the program is opened.
In fact, it is written a cppmake.m file, its function is similar to makefile, in fact, the implementation of the MEX compile this project when the compilation rules. You can look at the code in the back and know what's going on inside.
% this cppmake.m are for matlab% function:compile C + + files which rely on OpenCV for MATLAB using mex% Modified by Jessica % date:2014-9-10% homepage:http://www.cnblogs.com/lukylu/% Email: [email protected]% Matlab and C + + mixed PR Ogramming (dependent on OpenCV Library)% first step (before exeuting the program): Use ' mex-setup ' to choose your C + + Co Mpilerclear all;% Get The architecture of this computeris_64bit = strcmp (computer, ' MACI64 ') | | strcmp (computer, ' GLNXA64 ') | | strcmp (computer, ' PCWIN64 ');%---------------------------------------------------------------------------------- ------------percent of the configuration of compiler% need to modify this configuration according to your own path of OpenCV % Notice:if your system is 64bit, your OpenCV must be 64bit! Out_dir= './'; Cppflags = '-o-dndebug-i.\-if:\opencv\build\include-if:\opencv\build\include\opencv-if:\opencv\build\include\ Opencv2 '; % your OpenCV "include" path ldflags = '-lf:\opencv\build\x86\vc10\lib '; % your OpenCV "lib" Path%libs = '-lopencv_calib3d249d-lopencv_contrib249d-lopencv_core249d-lopencv_features2d249d-l OPENCV_FLANN249D-LOPENCV_GPU249D-LOPENCV_HIGHGUI249D-LOPENCV_IMGPROC249D-LOPENCV_LEGACY249D-LOPENCV_ML249D- Lopencv_nonfree249d-lopencv_objdetect249d-lopencv_photo249d-lopencv_stitching249d-lopencv_ts249d-lopencv_ VIDEO249D-LOPENCV_VIDEOSTAB249D '; LIBS = '-lopencv_calib3d249-lopencv_contrib249-lopencv_core249-lopencv_features2d249-lopencv_flann249-lopencv_ Gpu249-lopencv_highgui249-lopencv_imgproc249-lopencv_legacy249-lopencv_ml249-lopencv_nonfree249-lopencv_ objdetect249-lopencv_photo249-lopencv_stitching249-lopencv_ts249-lopencv_video249-lopencv_videostab249 '; if Is_ 64bit Cppflags = [cppflags '-largearraydims ']; End% Add your files here!! Compile_files = {%the List of your code files which need to be compiled ' ImageCalibration.cpp '};%-------------- -------------------------------------------------------------------------------- %---------------------------------------------------------------------------------- ------------percent Compilingfor k = 1:length (compile_files) str = compile_files{k}; fprintf (' Compilation of:%s\n ', str); str = [str '-outdir ' out_dir cppflags ldflags LIBS]; args = RegExp (str, ' \s+ ', ' split '); Mex (args{:}); End fprintf (' Congratulations, compilation successful!!! \ n ');%----------------------------------------------------------------------------------------------
Note: Before calling this CPPMAKE.M file, select the compiler and use the MEX-SETUP directive.
The 21st behavior configuration OpenCV include path, for the high version of OpenCV there are 3 include,-i to fill in the OpenCV of your computer's include path, the use of spaces between the multiple paths is "open." For example, My Computer OpenCV installed on the F drive, so the path is F:\opencv\build\include ....
The 22nd behavior configures the path of the OpenCV Lib library to start with-L. 23rd, 24 behavior Add the name of the OpenCV DLL library, the-l start, separated by a space between the different libraries.
第25-27 line, 64-bit system required.
Add the file name of the MEX function you want to compile at line 32. OK, the first step is completed, run this m file directly to complete the configuration, compilation.
The second step: reference to other MATLAB and C + + mixed programming method of the MEX function can be.
Hurry up, write this first, and add it later.
Iv. references
[1] matlab and C + + mixed programming (dependent OPENCV library)
[2] Matlab call OpenCV function method and Matlab compile C + + program
[3] MATLAB compiled CPP file with MEX
[go] matlab mixed with C + + programming, add OpenCV Library