1

我正在尝试在 Matlab 中编译 C++ 代码。源代码使用 OpenCV 库。当我写:

mex myfile.cpp

我收到以下错误:

致命错误 C1083:无法打开包含文件:'opencv2/opencv.hpp' 没有这样的文件或目录

我正在使用 Matlab r2012b 并在 Windows 7 上使用 Visual c++ 2010 express。

请问有什么解决办法吗?

谢谢你。

编辑:我做了以下但得到另一个错误:

 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. 
4

2 回答 2

1

您应该将包含标志和链接库添加到命令行。那是,

mex myfile.cpp -I header_path -l opencv_libraries

于 2012-11-26T14:35:23.723 回答
1

请试试:

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

顺便说一句,您链接 opencv_< > d .lib 而不是 opencv_< >.lib 文件是否有特殊原因?

于 2012-11-26T15:37:01.177 回答