qt5.3.1+opencv2.4.9編譯環境的搭建

到官網下載qt-opensource-windows-x86-mingw482_opengl-5.3.1.exe文件,執行該文件,選擇默認安裝便可實現QT的安裝(安裝在C盤的根目錄下),該文件封裝好了Qt librariesQt Creator,其中Qt Creator3.1.2版本。 html

到官網http://opencv.org/downloads.html下載OpenCV for Windows2.4.9版本——opencv-2.4.9.exe。執行該文件,把它解壓到適當的目錄下便可,我是把它放到了c盤的根目錄下,即c:\opencv windows

 

http://www.cmake.org/cmake/resources/software.html下載cmake-3.0.1-win32-x86.exe文件。安裝cmake,安裝在C:\CMake目錄下。 ide

 

設置系統的環境變量,即把C:\Qt\Qt5.3.1\Tools\MinGW\bin加入系統的Path環境變量中,由於在CMake編譯過程當中會用到該目錄下的庫。 ui

 

在桌面上點擊CMake(cmake-gui)圖標,執行CMakeWhere is the source code欄和Where to build thebinaries欄中分別C:/opencv/sourecesopencvC:/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按鈕,開始配置,這時會出現以下的相似錯誤提示: this

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

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. 3d

CMake Error: Error required internal CMakevariable not set, cmake may be not be built correctly. code

Missing variable is: htm

CMAKE_CXX_COMPILER_ENV_VAR ci

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!

找到NameCMAKE_MAKE_PROGRAM的一項,把它的Value填寫爲C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/mingw32-make.exe便可。再次點擊Configure,這時不會提示任何錯誤,代表配置成功。

咱們還須要把QT加上,找到WITH,把它下面的WITH_QTWITH_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_DIRQt5Core_DIRQt5Gui_DIRQt5Test_DIRQt5Widgets_DIRQt5OpenGL_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.,但不用去管,按GenerateGenerate完成後,關閉CMake窗口。

打開系統的命令終端,進入C:\opencv\MinGW目錄,執行mingw32-make命令,這須要一段時間,該命令執行完後,再執行mingw32-make install命令。這樣可用於Qtopencv庫文件就生成了。

再次添加系統的Path環境變量,內容爲:c:\Qt\Qt5.3.1\5.3\mingw482_32\bin;c:\opencv\MinGW\bin

之後咱們用Qt Creator編譯opencv的時候,在建立一個新工程後,還須要在該工程的工程文件.pro文件內添加下列語句:

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

 

完成!

相關文章
相關標籤/搜索