在桌面上点击CMake(cmake-gui)图标,执行CMake,在Where is the source code栏和Where to build thebinaries栏中分别C:/opencv/soureces为opencv和C:/opencv/MinGW。C:/opencv/MinGW为编译后库文件所存放的目录,需要自己创建该目录。然后点击configure按钮,打开新的窗口,在Specify the generator for this project下选择MinGW Makefiles,然后选择Specify native compilers,点击Next按钮,打开新的窗口,在C一栏中填写C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/gcc.exe,在C++一栏中填写C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/g++.exe,Fortran不填写。然后点击Finish按钮,开始配置,这时会出现如下的类似错误提示:
C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/gcc.exe,在C++一栏中填写C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/g++.exe,Fortran不填写。然后点击Finish按钮,开始配置,这时会出现如下的类似错误提示:
CMake Error: CMake was unable to find abuild program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different buildtool.
CMake Error: CMake was unable to find abuild program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different buildtool.
CMake Error: Error required internal CMakevariable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Could not find cmake modulefile: C:/opencv/MinGW/CMakeFiles/3.0.1/CMakeCXXCompiler.cmake
CMake Error: Error required internal CMakevariable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Could not find cmake modulefile: C:/opencv/MinGW/CMakeFiles/3.0.1/CMakeCCompiler.cmake
Configuring incomplete, errors occurred!
找到Name为CMAKE_MAKE_PROGRAM的一项,把它的Value填写为C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/mingw32-make.exe即可。再次点击Configure,这时不会提示任何错误,表明配置成功。
我们还需要把QT加上,找到WITH,把它下面的WITH_QT和WITH_OPENGL选上,再次Configure。这时会出现类似下面的错误提示:
CMake Error atC:/CMake/share/cmake-3.0/Modules/FindQt4.cmake:1316 (message):
Found unsuitable Qt version "" from NOTFOUND, this coderequires Qt 4.x
Call Stack (most recent call first):
cmake/OpenCVFindLibsGUI.cmake:34 (find_package)
CMakeLists.txt:466 (include)
找到QT_QMAKE_EXECUTABLE,它的值填写为:C:/Qt/Qt5.3.1/5.3/mingw482_32/bin/qmake.exe
找到QT_MKSPECS_DIR,它的值填写为:C:/Qt/Qt5.3.1/5.3/mingw482_32/mkspecs
找到QT_QTCORE_LIBRARY_DEBUG,它的值填写为:C:/Qt/Qt5.3.1/5.3/mingw482_32/bin/Qt5Cored.dll
找到QT_QTCORE_LIBRARY_RELEASE,它的值填写为C:/Qt/Qt5.3.1/5.3/mingw482_32/bin/Qt5Core.dll
找到QT_QTCORE_INCLUDE_DIR,它的值填写为C:/Qt/Qt5.3.1/5.3/mingw482_32/include/QtCore/5.3.1/QtCore
再次点击Configure,这时会出现类似下面的错误提示:
CMake Error atC:/CMake/share/cmake-3.0/Modules/FindQt4.cmake:1316 (message):
Found unsuitable Qt version "5.3.1" from
C:/Qt/Qt5.3.1/5.3/mingw482_32/bin/qmake.exe, this code requires Qt 4.x
Call Stack (most recent call first):
cmake/OpenCVFindLibsGUI.cmake:34 (find_package)
CMakeLists.txt:466 (include)
在Ungrouped Entries下找到Qt5Concurrent_DIR,Qt5Core_DIR,Qt5Gui_DIR,Qt5Test_DIR,Qt5Widgets_DIR,Qt5OpenGL_DIR,它们的Value分别填写为:
C:/Qt/Qt5.3.1/5.3/mingw482_32/lib/cmake/Qt5Concurrent
C:/Qt/Qt5.3.1/5.3/mingw482_32/lib/cmake/Qt5Core
C:/Qt/Qt5.3.1/5.3/mingw482_32/lib/cmake/Qt5Gui
C:/Qt/Qt5.3.1/5.3/mingw482_32/lib/cmake/Qt5Test
C:/Qt/Qt5.3.1/5.3/mingw482_32/lib/cmake/Qt5Widgets
C:/Qt/Qt5.3.1/5.3/mingw482_32/lib/cmake/Qt5OpenGL
再次Configure,这时配置完成,不会出现任何错误提示。虽然会有许多警告,如This warning is for project developers. Use -Wno-dev to suppress it.,但不用去管,按Generate。Generate完成后,关闭CMake窗口。
INCLUDEPATH+=c:\opencv\build\include\opencv\
c:\opencv\build\include\opencv2\
c:\opencv\build\include
LIBS+=c:\opencv\MinGW\lib\libopencv_calib3d249.dll.a\
c:\opencv\MinGW\lib\libopencv_contrib249.dll.a\
c:\opencv\MinGW\lib\libopencv_core249.dll.a\
c:\opencv\MinGW\lib\libopencv_features2d249.dll.a\
c:\opencv\MinGW\lib\libopencv_flann249.dll.a\
c:\opencv\MinGW\lib\libopencv_gpu249.dll.a\
c:\opencv\MinGW\lib\libopencv_highgui249.dll.a\
c:\opencv\MinGW\lib\libopencv_imgproc249.dll.a\
c:\opencv\MinGW\lib\libopencv_legacy249.dll.a\
c:\opencv\MinGW\lib\libopencv_ml249.dll.a\
c:\opencv\MinGW\lib\libopencv_objdetect249.dll.a\
c:\opencv\MinGW\lib\libopencv_video249.dll.a