Created
October 8, 2018 09:04
-
-
Save yiminglin-ai/5b11cab5c7799eb999b7426c6debc2e8 to your computer and use it in GitHub Desktop.
[Compile Opencv using mex ] compile c++ files which rely on OpenCV3 for Matlab using mex #opencv #matlab #mex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%// This make.m is for MATLAB | |
%// Function: compile c++ files which rely on OpenCV for Matlab using mex | |
%// Author : zouxy | |
%// Date : 2014-03-05 | |
%// HomePage : http://blog.csdn.net/zouxy09 | |
%// Email : [email protected] | |
%// Modified by Yiming Lin to support OpenCV3 and Ubuntu | |
%// Date 2018-10-08 | |
%% Please modify your path of OpenCV | |
%% If your have any question, please contact Zou Xiaoyi | |
% Notice: first use "mex -setup" to choose your c/c++ compiler | |
clear all; | |
%------------------------------------------------------------------- | |
%% get the architecture of this computer | |
is_64bit = strcmp(computer,'MACI64') || strcmp(computer,'GLNXA64') || strcmp(computer,'PCWIN64'); | |
%------------------------------------------------------------------- | |
%% the configuration of compiler | |
% You 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 = ' -I/usr/local/include/ -I/usr/local/include/opencv/ -I/usr/local/include/opencv2/ '; % your OpenCV "include" path %% These flags can be generated using `pkg-config --cflags opencv` | |
LDFLAGS = ' -L/usr/local/lib/'; % your OpenCV "lib" path If the system is x86, changes the path to the x86 path accordingly. LIBS = ' -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_cudawarping -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_cudaarithm -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core -lopencv_cudev '; | |
%% These flags can be generated using `pkg-config --libs opencv` | |
if is_64bit | |
CPPFLAGS = [CPPFLAGS ' -largeArrayDims']; | |
end | |
%% add your files here! | |
compile_files = { | |
% the list of your code files which need to be compiled | |
'OpenCV_test1.cpp', | |
'OpenCV_test2.cpp' | |
}; | |
%------------------------------------------------------------------- | |
%% compiling... | |
for k = 1 : length(compile_files) | |
str = compile_files{k}; | |
fprintf('compilation of: %s\n', str); | |
str = [str CPPFLAGS LDFLAGS LIBS]; | |
args = regexp(str, '\s+', 'split'); | |
mex(args{:}); | |
end | |
fprintf('Congratulations, compilation successful!!!\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment