How to connect Matlab 2013b with OpenCV2.4.5 on 64-bit Windows7 using MS Studio 2010

  • Modify system Path to add following opencv path: C:\OpenCV2.4.5\build
  • Perform mex setup and select MS Studio 2010 as your preferred compiler
  • Open mexopts.bat , find it using the command: >> fullfile(prefdir,’mexopts.bat’)
  • add at the end these lines :

rem rem ************
rem rem OpenCV2.4.5
rem rem ************
set OCVDIR=C:\OpenCV2.4.5\build
set LIB=%OCVDIR%\x64\vc10\lib; %LIB%
set PATH=%OCVDIR%\x64\vc10\bin; %OCVDIR%\bin; %PATH%

  • In the same file look for the section “Linker parameters”, after that add the different lib files of OpenCV to the end of the set LINKFLAGS= line of the command:

opencv_calib3d245.lib opencv_calib3d245d.lib opencv_contrib245.lib opencv_contrib245d.lib opencv_core245.lib opencv_core245d.lib opencv_features2d245.lib opencv_features2d245d.lib opencv_flann245.lib opencv_flann245d.lib opencv_gpu245.lib opencv_gpu245d.lib opencv_haartraining_engine.lib opencv_haartraining_engined.lib opencv_highgui245.lib opencv_highgui245d.lib opencv_imgproc245.lib opencv_imgproc245d.lib opencv_legacy245.lib opencv_legacy245d.lib opencv_ml245.lib opencv_ml245d.lib opencv_objdetect245.lib opencv_objdetect245d.lib opencv_video245.lib opencv_video245.lib

  • Now, all you have to do is restart Matlab and do not forget to save “MEXOPTS.BAT”