1.软件版本及下载地址:
Opencv3.1.0 http://opencv.org/downloads.html
opencv_contrib http://www.cnblogs.com/Geo-fortune/p/4822997.html
QT 5.1.0 https://download.qt.io/archive/qt/5.1/5.1.0/
Cmake2.4.5 https://cmake.org/download/
或者直接在这个百度云盘下载
http://pan.baidu.com/s/1c1FMMbQ
这个云盘里面不包括QT安装包
2.
Opencv3.1.0直接解压安装
QT5.1.0直接解压安装
Cmake直接解压即可
Opencv_contrib解压即可
注意:以上所有的文件文件路径都都不能有空格
我的文件夹结构
Cmake文件夹中存放cmake文件
Opencv文件夹存放opencv文件
opencvBinary 存放opencv和opencvContrib编译后的二进制文件
opencvContrib存放opencvContrib文件
QT存放QT解压安装后的文件
3.检查文件的完整性
(1)检查opencv/source是否是以下的内容,下载的opencv可能会缺少一些文件
(2)检查opencv/source/3rdparty
看一下是否存在libwebp文件夹
4. 设置环境变量
将
D:\QTINSTALL\QT\Tools\mingw48_32\bin;
D:\QTINSTALL\cmake\bin;
D:\QTINSTALL\QT\5.1.0\mingw48_32\bin;
这三个路径添加到环境变量中
5. 改变.cmake文件
将
D:\QTINSTALL\opencv\sources\cmake文件下的OpenCVCompilerOptions.cmake打开,
找到
add_extra_compiler_option(-Werror=non-virtual-dtor)
将其变为
# add_extra_compiler_option(-Werror=non-virtual-dtor)
6. 打开cmke/bin/cmake-gui,设置源文件目录和目标文件目录
(1)源文件目录必须为包含CmakeLists.txt文件的opencv目录
我的源文件目录为: D:\QTINSTALL\opencv\sources
(2)目标文件目录可以自行设置,用于保存cmake编译opencv后的二进制代码,我设置的目录为D:\QTINSTALL\opencvBinary
编译器选择Specify native compilers,点击next
C编译器选择 D:/QTINSTALL/QT/Tools/mingw48_32/bin/gcc.exe
C++编译器选择 D:/QTINSTALL/QT/Tools/mingw48_32/bin/g++.exe
点击next
勾选Grouped,在ungrouped Entntries中设置下面几个文件目录
设置为如图所示的文件路径
在Ungrouped Entries下找到Qt5Concurrent_DIR,Qt5Core_DIR,Qt5Gui_DIR,Qt5Test_DIR,Qt5Widgets_DIR,Qt5OpenGL_DIR,它们的Value分别填写为:
d:/opencv/Qt/Qt5.5.0/5.5/mingw482_32/lib/cmake/Qt5Concurrent
d:/opencv/Qt/Qt5.5.0/5.5/mingw482_32/lib/cmake/Qt5Core
d:/opencv/Qt/Qt5.5.0/5.5/mingw482_32/lib/cmake/Qt5Gui
d:/opencv/Qt/Qt5.5.0/5.5/mingw482_32/lib/cmake/Qt5Test
d:/opencv/Qt/Qt5.5.0/5.5/mingw482_32/lib/cmake/Qt5Widgets
d:/opencv/Qt/Qt5.5.0/5.5/mingw482_32/lib/cmake/Qt5OpenGL
点击configure,出现如下界面
勾选WITH_QT WITH_OPENGL WITH_PNG
去掉WITH_CUDA
在
这一栏中添加opencv_contrib的文件位置
如下
点击configure,出现如下提示
9.出现Configuring done 说明暂时没有问题,
单击register按钮,registering done后
关闭cmake软件
9 在cmake设置的目标文件夹中的空闲位置,例如我的位置是
按住shift+右键单击,显示一个 打开命令行 ,打开后
,执行mingw-32命令,如下图所示
此时,需要关闭杀毒软件以及其他防卫软件
此过程大约需要30分钟左右
10.执行mingw32-make install
大约需要两三分钟
11.进一步配置环境变量
将D:\QTINSTALL\opencvBinary文件夹里面的文件只留下bin和lib文件夹,其余文件都删除
将D:\QTINSTALL\opencv\build文件夹下的include文件夹拷贝到D:\QTINSTALL\opencvBinary\文件夹下面,得到如下目录结构
再将bin目录即D:\QTINSTALL\opencvBinary\bin
添加到环境变量中
12.
新建QT文件,在.pro文件最后面加下面几行代码进行配置
INCLUDEPATH+=D:\InstallOpencv\opencvBinary\include\opencv\
D:\InstallOpencv\opencvBinary\include\opencv2\
D:\InstallOpencv\opencvBinary\include
LIBS+= D:\InstallOpencv\opencvBinary\lib\libopencv_bgsegm310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_bioinspired310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_calib3d310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_ccalib310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_core310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_cvv310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_datasets310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_dnn310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_dpm310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_face310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_features2d310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_flann310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_fuzzy310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_highgui310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_imgcodecs310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_imgproc310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_line_descriptor310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_ml310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_objdetect310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_phase_unwrapping310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_photo310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_plot310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_reg310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_rgbd310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_saliency310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_shape310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_stereo310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_stitching310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_structured_light310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_superres310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_surface_matching310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_text310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_tracking310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_video310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_videoio310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_videostab310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_xfeatures2d310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_xobjdetect310.dll.a\
D:\InstallOpencv\opencvBinary\lib\libopencv_xphoto310.dll.a
13.完成全部安装
在安装过程中会出现的问题
1.
CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
原因:
没有c和C++的编译工具。
(1)这是由于QT Creator中没有MinGW编译器,需要下载MinGW编译器,再按照步骤http://wenku.baidu.com/view/602cad4cb7360b4c2f3f6429.html
将MinGW编译器整合到QT Creator中
(2)或者没有将bin文件夹加入到环境变量中
按照上面安装步骤所写的第四步进行即可
2.
查看D:/QTINSTALL/opencvBinary/CMakeFiles/CMakeOutput.log
“E:/C++” “MATCHES” “^E:/C++/Opencv 3.0/opencv/sources” “OR” “E:/C++” “MATCHES” “^E:/C++”
Regular expression “^E:/C++/Opencv 3.0/opencv/sources” cannot compile
Call Stack (most recent call first):
CMakeLists.txt:354 (ocv_include_directories)
这个解释是说cmake的安装包里面有空格或者有加号
寻求网上的原因:
http://www.cnblogs.com/sn-dnv-aps/p/4561939.html
做出如下变化
修改 opencv/sources/CMakeLists.txt
行数: 174
OCV_OPTION(WITH_IPP …..) 将ON 修改为OFF
行数: 179
OCV_OPTION(WITH_OPENEL ….) 将OFF 修改为ON
行数: 185
OCV_OPTION(WITH_QT ….) 将 OFF 修改为 ON
3. 下载opencv_ffmpeg.dll出现问题
这是由于国内的网络问题使得opencv_ffmped.dll不能下载完成
解决办法:
下载Opencv_ffmpeg.dll
http://download.csdn.net/download/kelvin_yan/9710789
下载文件,替换到opencv/3rdparty/ffmepg文件夹下面
4.下载protobuf-cpp-3.1.0.tar.gz出现问题
解决方案
下载protobuf-cpp-3.1.0
http://download.csdn.net/download/lql0716/9738154
将文件放在D:\QTINSTALL\opencvContrib\modules\dnn.download\bd5e3eed635a8d32e2b99658633815ef\v3.1.0
注意:在出现错误提示后,不能清除cmake的缓存,或者关闭cmake,只能点击cmake界面的stop按钮,将
文件直接替换,注意:不能解压!
5. 出现 ocv_add_testdata
解决方案
打开D:\QTINSTALL\opencvContrib\modules\text文件夹下的文件CMakeLists.txt,将最后三行进行注释,注释为如下形式
6.提示:下载vgg_generated_*.i出现问题
原因:网络问题
解决方案
在http://answers.opencv.org/question/113942/cmake-failing-with-hash-mismatch/上所提到的链接上下载所需的文件,
将文件将文件vgg_generated_*.i替换到D:\QTINSTALL\opencvContrib\modules\xfeatures2d\cmake.download\151805e03568c9f490a5e3a872777b75
文件夹下的文件
8. 这种use –Wno-dev warning可以忽略
9.在cmd中执行mingw32-make出现问题的时候,需要查看提示,根据提示删除不需要的opencv-contrib文件夹
https://github.com/opencv/opencv_contrib/tree/master/modules
可以看到每个模块的具体功能
当我的包中有aruco模块 和ximgproc模块时,会提示错误。此时,需要将opencv-contrib/modules/文件中发生错误的模块删除,用cmake重新编译,再在cmd中执行mingw32-make