1
votes

I am trying to compile a C++ code in Matlab. The source code uses the OpenCV library. when I write:

mex myfile.cpp

I get the following Error:

fatal error C1083: Cannot open include file: 'opencv2/opencv.hpp' No such file or directory

I am using Matlab r2012b and have Visual c++ 2010 express on windows 7.

Is there please any solution for this?

Thank you.

Edit: I did the following but get another error:

 mex -v -largeArrayDims Calib.cpp -I"C:\opencv\build\include" ... 
-L"C:\opencv\build\x86\vc10\lib"  -lopencv_calib3d240d -lopencv_core240d ... 
-lopencv_highgui240d -lopencv_imgproc240d -llibCam


->     Default options filename found in C:\Users\Ali\AppData\Roaming\MathWorks\MATLAB\R2012b 
    ---------------------------------------------------------------- 
    ->    Options file           = C:\Users\Ali\AppData\Roaming\MathWorks\MATLAB\R2012b\mexopts.bat 
          MATLAB                 = C:\Programmes\MATLAB\R2012b 
    ->    COMPILER               = cl 
    ->    Compiler flags: 
             COMPFLAGS           = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD 
             OPTIMFLAGS          = /O2 /Oy- /DNDEBUG 
             DEBUGFLAGS          = /Z7 
             arguments           =  -IC:\opencv\build\include 
             Name switch         = /Fo 
    ->    Pre-linking commands   =  
    ->    LINKER                 = link 
    ->    Link directives: 
             LINKFLAGS           = /dll /export:mexFunction /LIBPATH:"C:\Programmes\MATLAB\R2012b\extern\lib\win32\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\templib.x" /MAP:"Calib.mexw32.map" 
             LINKDEBUGFLAGS      = /debug /PDB:"Calib.mexw32.pdb" 
             LINKFLAGSPOST       =  
             Name directive      = /out:"Calib.mexw32" 
             File link directive =  
             Lib. link directive =  
             Rsp file indicator  = @ 
    ->    Resource Compiler      = rc /fo "mexversion.res" 
    ->    Resource Linker        =  
    ---------------------------------------------------------------- 


    --> cl  -IC:\opencv\build\include /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\Calib.obj -IC:\Programmes\MATLAB\R2012b\extern\include -IC:\Programmes\MATLAB\R2012b\simulink\include /O2 /Oy- /DNDEBUG Calib.cpp 

    Calib.cpp 
        Contents of C:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\mex_tmp.rsp: 
      C:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\Calib.obj 


    --> link /out:"Calib.mexw32" /dll /export:mexFunction /LIBPATH:"C:\Programmes\MATLAB\R2012b\extern\lib\win32\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\templib.x" /MAP:"Calib.mexw32.map"  @C:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\mex_tmp.rsp  C:\opencv\build\x86\vc10\lib\libCam.lib 
    C:\opencv\build\x86\vc10\lib\opencv_calib3d240d.lib C:\opencv\build\x86\vc10\lib\opencv_core240d.lib C:\opencv\build\x86\vc10\lib\opencv_highgui240d.lib C:\opencv\build\x86\vc10\lib\opencv_imgproc240d.lib  

    LINK : error LNK2001: symbole externe non résolu mexFunction 
    C:\Users\Ali\AppData\Local\Temp\mex_LVNr2V\templib.x : fatal error LNK1120: 1 externes non résolus 

      C:\PROGRA~3\MATLAB\R2012B\BIN\MEX.PL: Error: Link of 'Calib.mexw32' failed. 

    Error using mex (line 206)
    Unable to complete successfully. 
2

2 Answers

1
votes

You should add include flags and linking libraries to the command line. That is,

mex myfile.cpp -I header_path -l opencv_libraries

1
votes

Please try:

mex -largeArrayDims Calib.cpp -IC:\opencv\build\include -LC:\opencv\build\x86\vc10\lib...
 -l opencv_calib3d240d -l opencv_core240d -l opencv_highgui240d -l opencv_imgproc240d

BTW, is there a special reason why you link with the opencv_< >d.lib rather than opencv_< >.lib files?