Qt+Opencv+cmake在win10系统下的完美配置

升级了系统,在win10环境下进行Qt+Opencv+CMake的配置

之前在win7系统下的配置链接:http://blog.csdn.net/sinat_36420785/article/details/60906140
本文参考:https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows


Qt:5.9.1            
             下载链接:https://www.qt.io/download-open-source/
OpenCV:3.2.0
             下载链接:https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.2.0/
CMake:3.7.2
             下载链接: https://cmake.org/files/v3.7/cmake-3.7.2-win64-x64.msi

在D盘下创建新文件夹(Qt-Opencv),将Qt5.9.1,Opencv3.2.0和CMake放在D:\Qt-Opencv\下。

安装Qt:
Welcome to the Qt online installer: next
Qt Account - your unified login to everything Qt: skip
Setup-Qt: next
installation folder: D:\Qt-Opencv\Qt
select components: Qt-Qt5.9-MingGW 5.3.0 32 bit
select components: Qt-Tools-MinGW 5.3.0    
License Agreement: agree and next
start menu shortcuts: next
ready to install: install

按照上述流程安装Qt, 一定要勾选Qt-Qt5.9-MingGW 5.3.0 32 bit和Qt-Tools-MinGW 5.3.0
在D:\Qt-Opencv\Qt\Tools\QtCreator\bin\qtcreator.exe,即为QtCreator。
此时要配置环境变量,添加环境变量 Path,D:\Qt-Opencv\Qt\Tools\mingw530_32\bin;

安装OpenCV
点击opencv-3.2.0-vc14.exe直接运行,安装在D:\Qt-Opencv\Opencv-3.2.0目录下。

安装CMake:
Welcome to the CMake etup Wizzard: next
End-User License Agreement:  勾选Accept and next
Install options: 勾选 Add CMake to the system PATH for all users, next
Destination folder: C:\Program Files\CMake (default), next
Ready to install CMake, Install

配置Opencv

运行CMake(C:\Program Files\CMake\bin\cmake-gui.exe),然后:

Where is the source code: D:\Qt-Opencv\opencv-3.2.0\sources
Where to build the binaries: D:\opencv-build

点击finish,然后cmake进行配置。
勾选WITH_OPENGL和WITH_QT,去除掉WITH_IPP;
再次configure;

对出现的红色部分进行选择:
Set QT_MAKE_EXECUTABLE to D:\Qt\5.9\mingw53_32\bin\qmake.exe
Set Qt5Concurrent_DIR to D:\Qt\5.9\mingw53_32\lib\cmake\Qt5Concurrent
Set Qt5Core_DIR to D:\Qt\5.9\mingw53_32\lib\cmake\Qt5Core
Set Qt5Gui_DIR to D:\Qt\5.9\mingw53_32\lib\cmake\Qt5Gui
Set Qt5Test_DIR to D:\Qt\5.9\mingw53_32\lib\cmake\Qt5Test
Set Qt5Widgets_DIR to D:\Qt\5.9\mingw53_32\lib\cmake\Qt5Widgets
Set Qt5OpenGL_DIR to D:\Qt\5.9\mingw53_32\lib\cmake\Qt5OpenGL
Set CMAKE_BUILD_TYPE to Release or RelWithDebInfo
再次configure
configure done后点击generate,等待generate done;

在目录D:\Qt-Opencv\opencv-3.2.0\cmake\下找到OpenCVCompilerOptions.cmake文件。打开文件(我用记事本打开的),找到:add_extra_compiler_option(-Werror=non-vitural-dtor)将他注释掉,就是给其前面加一个井号键

添加环境变量Path:

D:\Qt-Opencv\Qt\Tools\ mingw53_32\bin;
D:\Qt-Opencv\Qt\5.9.1\ mingw53_32\bin;

运行cmd
d:
cd d:\
cd d:\Qt-Opencv
cd opencv-build 
mingw32-make (持续时间较长)
mingw32-make install

添加环境变量Path,D:\Qt-Opencv\opencv_mingw\install\x86\mingw\bin添加入系统环境变量

至此,在win10系统下对Qt5.9.1+OpenCV3.2.0的配置完成。

直到编译结束。然后输入命令:mingw32-make install ,大约一到两分钟就安装完成了。

   注意点:若编译期间出现如下错误:

    错误: ... windres.exe: unknown option -- W ...

    根据提示依据如下思路解决: in cmake uncheck ENABLE_PRECOMPILED_HEADERS

    即:mingw32-make ENABLE_PRECOMPILED_HEADERS -j 8

    http://answers.opencv.org/question/168538/building-opencv-with-mingw-gcc-710-and-cmake-390-windresexe-unknown-option-w/

    错误:in the file opencv/sources/modules/videoio/src/cap_dshow.cpp, you have the following error : 'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' was not declared in this scope ...

    解决:put the following line: #define NO_DSHOW_STRSAFE, before the line : #include "DShow.h"

    即:在D:\Qt\opencv3.4.0\opencv\source\modules\videoio\src\cap_dshow.cpp中,在#include “DShow.h“上一行中插入: #define NO_DSHOW_STRSAFE


 
  
 
  


 
  

 
  

猜你喜欢

转载自blog.csdn.net/sinat_36420785/article/details/79443418