Recently we have put together the whole project, the project is more complex. Because we do the retrieval system, so we use ASP. NET (C #), but the implementation of the algorithm is in MATLAB, so we have to use MATLAB to generate dynamic link library DLL, and then call Matlab in C #, this configuration problem alone for one weeks, However, the solution has been resolved, the resolution will have time to write a blog out later.
Although our entire project has been able to run through the C #, but the search effect is not ideal, check the various possible problems, the first is naturally the problem of characteristics. We do is partial image retrieval, some off-the-shelf feature extraction algorithm is implemented under OPENCV, need to use OPENCV to achieve feature extraction, so we have to use MATLAB to invoke OPENCV.
The last blog has already said how to use Mex to achieve mixed programming, also if the C + + code calls the OpenCV library, when the MEX compilation is no longer as simple as before. With MacOS and windows on hand, I'll tell you how to use MEX to compile C + + code with OPENCV calls.
First of all I use the MATLAB version is MATLAB2012A 64BIT,OPENCV version is installed with homebrew (the specific version forgot)
MacOS
Under the Apple system, I refer to this classmate's work: http://vision.is.tohoku.ac.jp/~kyamagu/software/mexopencv/, but because OS X's environment will conflict with the library that Matlab comes with. In OS X environment, runtime error can happen if the version of your system library conflicts with Matlab ' s internal Lib Rary. My conflict is dchar16_t's repeating macro definition, so I have a slightly different approach to that article.
OS X 10.9 and XCode 5
Due to the change in the default C + + runtime in OS X 10.9, you probably need to tweak a few configurations in to mexopts.sh
AVO ID compile issues. If you haven ' t run mex -setup
in Matlab, please do so first and edit and change mexopts.sh
a few variables. Following shows an example.
The above paragraph is intact copy and paste, and then he gives the method is to modify the/applications/matlab/matlab_r2012a.app/bin/mexopts.sh文件(这段路径是我自己的),如何修改这个文件,他给出了一个办法,但是这里我的修改略和他不同,请注意。首先打开mexopts.sh文件,并且找到maci64,
Some of the variables are then modified as follows (the image has been modified):
Cc= ' clang ' cxx= ' clang++ ' sdkroot= '/applications/xcode.app/contents/developer/platforms/macosx.platform/developer /sdks/macosx10.9.sdk/' macosx_deployment_target= ' 10.9 ' clibs= "$CLIBS-lc++" cxxflags= "-fno-common-no-cpp-precomp- Fexceptions-arch $ARCHS-isysroot $SDKROOT-mmacosx-version-min= $MACOSX _deployment_target-std=c++11-stdlib=libc++ " #注意这里和他的不同在我删除了-dchar16_t, this thing retains a macro definition conflict cxxlibs= "$MLIBS-lc++"
This configures the build environment under MacOS, then open matlab and enter mex-setup under Command window. Follow the steps to set up the MEX compilation configuration,
However, the above is only configured to compile the environment, only the use of MEX to compile the code of the pure and C + +, if you want to compile the code with the OPENCV function, you need to refer to the following blog: http://blog.csdn.net/raodotcong/article/ details/8785358. I did this because I installed OPENCV through homebrew, the installation path under/USR/LOCAL/CELLAR/OPENCV, so when I use MEX compilation it should be entered as follows: For example I am going to compile the CPP file (called the Code of the OpenCV Library):
Then enter the following in MATLAB:
Mex BofGabor.cpp Cvgabor.cpp Image.cpp retriever.cpp-i/usr/local/cellar/opencv/2.4.9/include-l/usr/local/cellar/ opencv/2.4.9/lib/-lopencv_highgui.2.4-lopencv_core.2.4.9-lopencv_imgproc.2.4.9
Explain the above command a little bit,
Mex BofGabor.cpp Cvgabor.cpp Image.cpp Retriever.cpp is to link four files together to generate a MEX file.
-i/usr/local/cellar/opencv/2.4.9/include is telling the compiler where to look for the header file.
-l/usr/local/cellar/opencv/2.4.9/lib/is telling the compiler where to look for library files
-lopencv_highgui.2.4-lopencv_core.2.4.9-lopencv_imgproc.2.4.9 the last three are the libraries that will be used to link up.
Finally, the bofgabor.mexmaci64 file will be generated ~ ~ ~
Windows
Under Windows is actually similar to MacOS under, just less the steps to modify that mexopts.sh file, tonight is too late, continue to write tomorrow ~
MATLAB and C + + mixed programming--Call OPENCV