【OpenCV】--Windows下配置OpenCV的Qt开发环境

时间:2023-01-20 09:07:11

文章转载自:http://blog.csdn.net/qiurisuixiang/article/details/8665278


1、下载所需工具

(1)Qt Creator 下载地址http://qt-project.org (建议下载最新版本,因为里面带的MinGW版本较高,我最开始使用Qt 4.7.4编译OpenCV-2.4.4一直报错,后来换成Qt 5.0.1编译成功)

(2)OpenCV 下载地址http://opencv.org/(不建议下载最新版本,最新版本的编译需要高版本的MinGW,不然在执行mingw32-make命令会报错)

(3)CMake 下载地址http://www.cmake.org/cmake/resources/software.html


 备注:为了方便使用,博主将软件集中打包上传,下载链接:http://pan.baidu.com/s/1c2nxAI8 密码:v22j

  Qt Creator:qt-opensource-windows-x86-mingw492-5.5.1

OpenCV :opencv-2.4.9.exe

CMake :cmake-3.5.2-win32-x86.msi


2 安装Qt Creator,过程很简单,一直下一步就OK

 

3 安装OpenCV,设置解压路径就OK

 

4 安装CMake,过程同样很简单(注意:(1)安装路径不能有中文和空格(2)勾选加入所有境变量中)

 

目前最新的OpenCV版本,安装之后的目录下面有源码和个版本的lib和dll,不过为避免出现问题,还是自己编译

 

将C:\Qt\Qt5.0.1\Tools\MinGW\bin加入系统的Path环境变量(假设Qt Creator安装在C盘

 

打开CMake,使用CMake编译OpenCV。配置源码路径与生成的目标路径

(1)源码路径:要选择OpenCV安装目录下含有如下文件的文件夹

(2)目标路径:可以随意设置

 【OpenCV】--Windows下配置OpenCV的Qt开发环境

点击Configure配置按钮。在弹出的对话框中选择MinGW makefiles,其余选项保持默认,点击Finish按钮,开始编译

【OpenCV】--Windows下配置OpenCV的Qt开发环境

 

9 CMake编译结束界面如下图,勾选生成列表中的WITH_OPENGL和WITH_QT两项,其他项最好不要改动

【OpenCV】--Windows下配置OpenCV的Qt开发环境

 

10 再次点击Configure按钮,红色消失

【OpenCV】--Windows下配置OpenCV的Qt开发环境

 

11 点击Generate按钮,生成makefile文件,成功后,底下会提示Generating done

【OpenCV】--Windows下配置OpenCV的Qt开发环境

 

12 打开cmd,进入刚才设置的目标路径(C:\OpenCV),输入mingw32-make命令开始编译

【OpenCV】--Windows下配置OpenCV的Qt开发环境

【OpenCV】--Windows下配置OpenCV的Qt开发环境


 

13. 执行mingw32-make install,此过程大约需要1到2分钟

【OpenCV】--Windows下配置OpenCV的Qt开发环境


14、下面开始配置Qt Creator的OpenCV开发环境,将bin目录添加到系统环境变量

【OpenCV】--Windows下配置OpenCV的Qt开发环境


15、至此Qt Creator下的OpenCV开发环境已经配置好,下面在Qt Creator下测试是否已经配置成功。


16、打开Qt Creator,新建一个空工程,然后添加一个cpp文件,任意命名。

       在pro文件中添加如下OpenCV的依赖文件

INCLUDEPATH+=C:\opencv249\opencv\build\include\opencv\
C:\opencv249\opencv\build\include\opencv2\
C:\opencv249\opencv\build\include
LIBS+=C:\openmakecv\bin\libopencv_calib3d249.dll\
C:\openmakecv\bin\libopencv_contrib249.dll\
C:\openmakecv\bin\libopencv_core249.dll\
C:\openmakecv\bin\libopencv_features2d249.dll\
C:\openmakecv\bin\libopencv_flann249.dll\
C:\openmakecv\bin\libopencv_gpu249.dll\
C:\openmakecv\bin\libopencv_highgui249.dll\
C:\openmakecv\bin\libopencv_imgproc249.dll\
C:\openmakecv\bin\libopencv_legacy249.dll\
C:\openmakecv\bin\libopencv_ml249.dll\
C:\openmakecv\bin\libopencv_objdetect249.dll\
C:\openmakecv\bin\libopencv_video249.dll\
C:\openmakecv\lib\libopencv_calib3d249.dll.a\
C:\openmakecv\lib\libopencv_contrib249.dll.a\
C:\openmakecv\lib\libopencv_core249.dll.a\
C:\openmakecv\lib\libopencv_features2d249.dll.a\
C:\openmakecv\lib\libopencv_flann249.dll.a\
C:\openmakecv\lib\libopencv_gpu249.dll.a\
C:\openmakecv\lib\libopencv_highgui249.dll.a\
C:\openmakecv\lib\libopencv_imgproc249.dll.a\
C:\openmakecv\lib\libopencv_legacy249.dll.a\
C:\openmakecv\lib\libopencv_ml249.dll.a\
C:\openmakecv\lib\libopencv_objdetect249.dll.a\
C:\openmakecv\lib\libopencv_video249.dll.a