一、编译环境

系统:Windows10旗舰版
cmake版本下载:3.9.2
QtMingw版本下载:qt-opensource-windows-x86-5.11.0.exe,太大了只能放网盘
opencv版本下载:opencv331_mingw

二、CMAKE安装

将下载的cmake解压。

完成后打开软件

三、OpenCV解压与编译

将下载的opencv解压。并且进入其目录。新建一个文件夹名为opencv331_mingwBuild

点击左下角configure,弹出对话框,选择MinGw Makefiles和Use default native compilers,点击Finish


c写对应的F:/Qt/Qt5.11.0/Tools/mingw530_32/bin/gcc.exe
c++写对应的F:/Qt/Qt5.11.0/Tools/mingw530_32/bin/g++.exe

又出现了报错
CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

其中CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
解决方案如下:
勾选Grouped,Advanced
将CMAKE_MAKE_PROGRAM项后面的路径设置为Qt安装路径下的路径如下所示:F:/Qt/Qt5.11.0/Tools/mingw530_32/bin/mingw32-make.exe,重新点击Configure,问题解决。

正在编译中:

保持默认勾选项:

在Search搜索框里面输入ENABLE_CXX11,找到ENABLE_CXX11项,勾选,启用c++11新特性,否则之后编译会出错:

清空搜索框,输入WITH_OPENCL_D3D11_NV,找到WITH_OPENCL_D3D11_NV项,如果不需要d3d功能,将其取消勾选,否则编译时有可能出错

其他选项说明:
BUILD_OPENCV_WORLD:开启后会包含opencv_world模块,将各个模块编译成一个opencv_worldxxx.lib文件,而不是十几个lib库文件。方便之后的部署和使用
CMAKE_BUILD_TYPE:指定编译的类型为Debug还是Release
BUILD_JAVA:开启java支持
取消勾选ENABLE_PRECOMPILED_HEADERS
之后重新点击configure,直到红颜色消失

添加Qt环境变量:F:\Qt\Qt5.11.0\5.11.0\mingw53_32\bin

config,勾选WITH_QT



设置路径:

设置 QT_MAKE_EXECUTABLE 为 F:/Qt/Qt5.11.0/5.11.0/mingw53_32/bin/qmake.exe
设置 Qt5Concurrent_DIR 为 F:/Qt/Qt5.11.0/5.11.0/mingw53_32/lib/cmake/Qt5Concurrent
设置 Qt5Core_DIR 为F:/Qt/Qt5.11.0/5.11.0/mingw53_32/lib/cmake/Qt5Core
设置 Qt5Gui_DIR 为 F:/Qt/Qt5.11.0/5.11.0/mingw53_32/lib/cmake/Qt5Gui
设置 Qt5Test_DIR 为F:/Qt/Qt5.11.0/5.11.0/mingw53_32/lib/cmake/Qt5Test
设置 Qt5Widgets_DIR 为 F:/Qt/Qt5.11.0/5.11.0/mingw53_32/lib/cmake/Qt5Widgets
设置 Qt5OpenGL_DIR 为F:/Qt/Qt5.11.0/5.11.0/mingw53_32/lib/cmake/Qt5OpenGL
设置 CMAKE_BUILD_TYPE 为 Release 或者 RelWithDebInfo

点击generate产生makefile文件

在空白处按shift+右键,点击在此处打开命令窗口打开cmd,输入make+回车进行编译,之后等待进度到100编译成功。不要使用-j选项进行多线程编译,因为容易编译出错

打开终端进行编译:

cd E:\OpenCV_3.3.1\opencv-build
mingw32-make
mingw32-make install


解决方法:
mingw32-make 不是内部或外部命令,原因,没有配置环境变量。
方法:
用everything搜索mingw32-make.exe。将它的路径,添加到path环境变量中。重启电脑,或者等待一会。在cmd中,mingw32-make就成为有效的命令了。


编译报错:

注意CMAKE不要安装在X86路径下!!!!!
重新安装后解决!!!!!
又出幺蛾子:

C:\Strawberry\c\bin\windres.exe: unknown option – W
Usage: C:\Strawberry\c\bin\windres.exe [option(s)] [input-file] [output-file]
The options are:
-i --input= Name input file
-o --output= Name output file
-J --input-format= Specify input format
-O --output-format= Specify output format
-F --target= Specify COFF target
–preprocessor= Program to use to preprocess rc file
–preprocessor-arg= Additional preprocessor argument
-I --include-dir=

Include directory when preprocessing rc file
-D --define [=] Define SYM when preprocessing rc file
-U --undefine Undefine SYM when preprocessing rc file
-v --verbose Verbose - tells you what it’s doing
-c --codepage= Specify default codepage
-l --language= Set language when reading rc file
–use-temp-file Use a temporary file instead of popen to read
the preprocessor output
–no-use-temp-file Use popen (default)
-r Ignored for compatibility with rc
@ Read options from
-h --help Print this help message
-V --version Print version information
FORMAT is one of rc, res, or coff, and is deduced from the file name
extension if not specified. A single file name is an input file.
No input-file is stdin, default rc. No output-file is stdout, default rc.
C:\Strawberry\c\bin\windres.exe: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
modules\core\CMakeFiles\opencv_core.dir\build.make:1638: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj’ failed
mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1
CMakeFiles\Makefile2:1640: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/all’ failed
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:161: recipe for target ‘all’ failed
mingw32-make: *** [all] Error 2
解决方案:
在cmake中 取消勾选 ENABLE_PRECOMPILED_HEADERS
编译成功:

mingw32-make install

四、Qt使用OpenCV

只需要在pro配置中写好路径:

起不来。。。。。。
需要勾选CMAKE_BUILD_TYPE:指定编译的类型为Debug模式,重新编译。。。。
改为debug版本,编译报错

sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA错误
…opencv/sources/modules/videoio/src/cap_dshow.cpp…
…‘sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA’ was not declared inthis scope …

解决方式:
在cap_dshow.cpp(目录在上面) 添加一行:
#define STRSAFE_NO_DEPRECATE

Running Windows Runtime device detection.
No winrtrunner.exe found.
系统找不到指定的路径。
系统找不到指定的路径。
运行闪退,debug提示:during startup program exited with code 0xc0000135

需要将E:\Install\opencv331_mingwBuild\install\x86\mingw\bin拷贝到工程E:\MyCodes\QtCodes\QtDemo\build-024_OpenCVImage-Desktop_Qt_5_11_0_MinGW_32bit-Debug\debug下
成功运行demo

我的Qt图像标签demo博客:
Qt C++版深度学习图像标注工具

【参考文献】

1.Cmake 编译opencv缺少出现下载ffmpeg相关库解决方案 - it610.com
https://www.it610.com/article/1281192054168240128.htm
2.(197条消息) OpenCV使用CMake和MinGW的编译安装及其在Qt配置运行_辉哈的博客-CSDN博客_mingw编译opencv
https://blog.csdn.net/huihut/article/details/78701814
3.(197条消息) idea启动tomcat出现‘D:\Programfiles‘ 不是内部或外部命令,也不是可运行的程序_Maxiao1204的博客-CSDN博客
https://blog.csdn.net/Maxiao1204/article/details/112014217
4.(197条消息) opencv 用minggw编译时,遇到的坑_竹叶青水的博客-CSDN博客
https://blog.csdn.net/JimBraddock/article/details/88579809
5.(197条消息) c++ 编译OpenCV-3.3.0过程及遇到的问题_Alex_z0897的博客-CSDN博客_c++ opencv 编译
https://blog.csdn.net/zoeou/article/details/79559189
6.(197条消息) Qt5配置opencv3.4.5_菜鸟小郭( ̄▽ ̄)的博客-CSDN博客
https://blog.csdn.net/weixin_38846780/article/details/116129164

Windows系统下使用Mingw编译并运行opencv教程相关推荐

  1. mingw版本下qt与HTML,QT5.10开发(2) 在Windows 10下使用MinGW编译 静态Qt 5.10 release版 详细过程...

    Qt建议安装动态链接Dbug版和编译安装静态链接release版 前提: 先安装动态链接Dbug版,方法:QT5.10开发(1)安装QT5.10 地址:http://blog.csdn.net/qq_ ...

  2. 使用qemu在windows系统下搭建树莓派3b环境运行RT-Thread

    需要下载的资源 表1 下载资源 序号 资源名称 下载地址 说明 1 raspi3b_run_rt_thread_in_Qemu.rar https://download.csdn.net/downlo ...

  3. Windows 平台下基于MinGW和Qt 的OpenCV 之CMake 项目配置

    1. MinGW 编译OpenCV 参考其他教程 2. 添加系统环境变量 OpenCV_DIR 如果有执行 mingw32-make install, 则为 build 目录下install 文件的完 ...

  4. Windows 系统下使用 MinGW + MSYS + GCC 编译 FFMPEG

    一定要按照顺序操作,否则你很可能持续遇到很多奇怪的问题(ffmpeg对编译系统版本要求比较高). 1. www.mingw.org: 下载并安装 MinGW 5.1.4 (http://jaist.d ...

  5. 在Windows系统下安装VirtualBox与Ubuntu的详细教程

    最近需要学习一些Linux的操作,然而操作系统是Win10的,又不想装双系统,主要是切换系统麻烦.经过在网上查找一些资料,简单对比了一下,个人认为比较适合初学者的就是VirtualBox+Ubuntu ...

  6. windows系统下_ffmpeg编译_2011年

    ffmpeg开源库在linux系统下弄的,是一个很全的音频和视频的编解码库要在windows下编译出用于开发的lib库确实比linux下要麻烦,百度了很久,参照别人的见解终于成功编译出自己需要的可以用 ...

  7. FFmpeg在Windows系统下的编译过程

    由于FFMpeg是基于Linux开发的开源项目,源代码和Windows下最常见的Visual Studio提供的C/C++编译器不兼容,因此它不能使用MSVC++编译.要想使用FFMpeg,最先要解决 ...

  8. 手把手教你在Windows下使用MinGW编译libav

    2019独角兽企业重金招聘Python工程师标准>>> 手把手教你在Windows下使用MinGW编译libav libav是在Linux下使用纯c语言开发的,不可避免的,libav ...

  9. 手把手教你在Windows下使用MinGW编译libav(参考libx264的编入)

    转自:http://www.th7.cn/Program/cp/201407/242762.shtml 手把手教你在Windows下使用MinGW编译libav libav是在Linux下使用纯c语言 ...

最新文章

  1. 2018帮助_字节跳动扶贫获“北京市扶贫协作奖”,一年帮助8万贫困人口增收
  2. mybatis-查询过程
  3. python list遍历删除_Python中list循环遍历删除数据的正确方法
  4. codeup 1128: 出租车费 贪心|找规律
  5. android jni fork()子进程不运行_Android高级面试谈谈Zygote的理解
  6. 北美地区IPv4地址已用完,网络IP地址告急?
  7. 如何将c语言中的文件,急求如何将下列C语言程序数据存储到文件中?
  8. codeblocks中文编码问题
  9. Hyperledger fabric 区块结构、交易结构
  10. Android --- GreenDao的实现(ORM框架)
  11. PhotoShop PS 教程 100例
  12. 业务安全漏洞挖掘归纳总结
  13. 卡方检验的统计量推导_如何通俗的理解A / B测试与卡方检验
  14. 程序员接私活完整攻略
  15. 12306对抢票软件“下手”了
  16. 喜马拉雅xm格式转化mp3_MTS视频格式转化
  17. Oracle11g下导入SDO_GEOMETRY类型的数据异常处理
  18. TF内存卡(SDHC)的传输规范
  19. 如何才能高效的学习,99%的人不知道的高效学习法
  20. python hdf5_安装HDF5 1.8 和H5PY--HDF5和python接口

热门文章

  1. 商鼎云 | 你的数据管家
  2. Conda镜像源错误 ConnectionError(ReadTimeoutError(“HTTPSConnectionPool(host=‘mirrors.tuna.tsinghua.edu.cn‘
  3. 如何瓜分会缩水的蛋糕?
  4. proteus如何添加stm32_一个应用软件程序员的单片机STM32零基础入门
  5. python控制树莓派风扇_三极管打造树莓派温控风扇
  6. ReentrantLock加锁(lock())、释放锁(unlock())的实现
  7. 顺序表(SeqList)
  8. 计算机二级有道和未来哪个好,图文测评有道词典笔2.0加强版和专业版哪个好?体验有什么区别呢?使用三年后分享...
  9. 计算机网络技术与网络信息安全,计算机网络技术与网络安全精讲.ppt
  10. 如何建立医院患者满意度测评指标体系