QT使用vs作编译器可以直接使用opencv,不需要cmake重新编译,花了一下午的时间来搭建环境。
资源下载地址如下:
1.VS2013:https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx
2.qt-opensource-windows-x86-msvc2013-5.6.0:http://mirror.bit.edu.cn/qtproject/archive/qt/5.6/5.6.0/qt-opensource-windows-x86-msvc2013-5.6.0.exe(由于是64位系统开始安装的64位的QT但是编译会出现计算机类型错误,后来选择32位QT可以成功)
3.Opencv2.4.9:http://opencv.org/downloads.html
4.Glut:https://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
第一步:安装VS2013、QT5.6、Opencv2.4.9并配置环境变量
安装完毕后添加QT和Opencv的环境变量,如下所示:
G:\postgraduate\biyesheji\QT5.6\5.6\msvc2013\bin(根据自己的QT安装目录添加)
G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\bin(32位系统只添加X86即可,64位系统最好将x64的目录也加入环境变量)
【计算机】->【(右键)属性】->【高级系统设置】->【高级(标签)】->【环境变量】->“双击”系统变量中的PATH->在变量值里面添加相应的路径。如图:
配置完环境变量,将下载的Glut解压,得到五个文件glut.dll, glut32.dll, glut.lib, glut32.lib,glut.h)
(1)把glut.h复制到x:\Program Files\Microsoft\Visual Studio 10.0\VC\include\gl文件夹中,如果没有gl这个文件夹则可以自己新建一个。(x是你安装VS的盘符号)
(2)把解压得到的glut.lib和glut32.lib放到静态函数库所在文件夹(即与include并排的lib文件夹下)。
(3)把解压得到的glut.dll和glut32.dll放到操作系统目录下面的system32文件夹内。(64位系统为C:\Windows\SysWOW64)
(注:如在开发应用程序时用到OpenGL辅助库函数,则还需下载相应动态链接库,包含glaux.dll, glaux.lib, glaux.h,相应步骤同上)
即完成了VS+OpenGL的环境搭建
第二步:配置VS2013+Opencv2.4.9
新建win32控制台项目,修改项目属性,更改包含目录如下所示:
添加上
D:\Program Files\opencv\build\include
D:\Program Files\opencv\build\include\opencv
D:\Program Files\opencv\build\include\opencv2 这三个目录。
更改库目录:添加上D:\Program Files\opencv\build\x86\vc10\lib这个路径。
链接库配置:
opencv_ml249d.lib
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_nonfree249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_videostab249d.lib
opengl32.lib
glut32.lib
glu32.lib
这里加入了三个OpenGl的库文件:opengl32.lib、glut32.lib、glu32.lib,这样就完成了VS2013+opencv+opengl的配置,关于opencv的配置可以参考浅墨大神的博客http://blog.csdn.net/poem_qianmo/article/details/19809337
第三步:配置QT和opencv
安装QT5.6后还需要安装dbg_amd64_6.12.2.633调试器,下载地址:http://www.codemachine.com/downloads.html选择Windows 7 Debugging Tools for Windows。
QT构建配置好后如下所示:
新建一个QT工程,在pro文件加入如下所示的库:
INCLUDEPATH+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\include \
G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\include\opencv \
G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\include\opencv2
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_ml249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_calib3d249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_contrib249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_core249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_features2d249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_flann249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_gpu249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_highgui249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_imgproc249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_legacy249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_objdetect249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_ts249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_video249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_nonfree249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_ocl249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_photo249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_stitching249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_superres249d.lib
LIBS+=G:\postgraduate\biyesheji\opencv2.4.9\opencv\build\x86\vc12\lib\opencv_videostab249d.lib
在main.cpp里编写测试程序:
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
cout<<"opencv"<
测试结果如下: