Win7_64bits下qt5.3.1+opencv2.4.9编译环境的搭建

博主QQ:1356438802

QQ群:473383394——UVC&OpenCV47




篇文章是我网上找的参考文章,下面黑色字体是原来的内容,红色字体和图片是我自己的内容。我自己的安装平台是:win7-64  


引言

首先搞清楚我们要什么。我们要在QT上开发基于opencv的应用程序,需要opencv lib的支持,那在QT开发平台有两种方式,MSVC和MinGW,MSVC-lib可以在VisualStudio开发也可在QTCreator开发,MinGW-lib可以在QTCreator开发。

Win7_64bits下qt5.3.1+opencv2.4.9编译环境的搭建_第1张图片


如果使用MSVC-lib,就直接安装上面的opencv-2.4.10.exe就可以得到。

如果要使用MinGW-lib就要用opencv源码重新编译。


这篇文章讲述的就是opencv源码如何编译出MinGW-lib。


一、 安装MinGW编译链

到官网下载qt-opensource-windows-x86-mingw482_opengl-5.3.1.exe文件,执行该文件,选择默认安装即可实现QT的安装(安装在C盘的根目录下),该文件封装好了Qt librariesQt Creator,其中Qt Creator3.1.2版本。


我的:qt-opensource-windows-x86-mingw482_opengl-5.3.0.exe

下载地址:http://download.qt.io/archive/

你想装什么,哪个版本,随便下!


 

二、下载opencv源码

到官网http://opencv.org/downloads.html下载OpenCV for Windows2.4.9版本——opencv-2.4.9.exe。执行该文件,把它解压到适当的目录下即可,我是把它放到了c盘的根目录下,即c:\opencv


我的:opencv-2.4.10.exe

下载地址:https://sourceforge.net/projects/opencvlibrary/files/

你想装哪个平台,哪个版本,随便下!

 

三、安装CMAKE

http://www.cmake.org/cmake/resources/software.html下载cmake-3.0.1-win32-x86.exe文件。安装cmake,安装在C:\CMake目录下。

 

设置系统的环境变量,即把C:\Qt\Qt5.3.1\Tools\MinGW\bin加入系统的Path环境变量中,因为在CMake编译过程中会用到该目录下的库。

 

四、用CMAKE编译opencv源码

1. 在桌面上点击CMake(cmake-gui)图标,执行CMake


2. 在Where is the source code栏和Where to build the binaries栏中分别C:/opencv/sourecesopencvC:/opencv/MinGW。

C:/opencv/MinGW为编译后库文件所存放的目录,需要自己创建该目录。


3. 然后点击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不填写


4. 然后点击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!

Win7_64bits下qt5.3.1+opencv2.4.9编译环境的搭建_第2张图片

找到NameCMAKE_MAKE_PROGRAM的一项,把它的Value填写为C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/mingw32-make.exe(对应自己的目录)即可。再次点击Configure,这时不会提示任何错误,表明配置成功。


5. 我们还需要把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)

Win7_64bits下qt5.3.1+opencv2.4.9编译环境的搭建_第3张图片

找到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(对应自己的目录)



6. 再次点击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)

Win7_64bits下qt5.3.1+opencv2.4.9编译环境的搭建_第4张图片

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



7. 再次Configure,这时配置完成,不会出现任何错误提示。虽然会有许多警告,如This warning is for project developers. Use -Wno-dev to suppress it.,但不用去管,按GenerateGenerate完成后,关闭CMake窗口。



8. 打开系统的命令终端,进入C:\opencv\MinGW目录,执行mingw32-make命令,这需要一段时间,该命令执行完后,

Win7_64bits下qt5.3.1+opencv2.4.9编译环境的搭建_第5张图片



9. 再执行mingw32-make install命令。这样可用于Qtopencv库文件就生成了。


10. 再次添加系统的Path环境变量,内容为:

c:\Qt\Qt5.3.1\5.3\mingw482_32\bin;c:\opencv\MinGW\bin



11. 以后我们用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

 

完成!

你可能感兴趣的:(openCV)