windows10通过mingw(Qt5.14)+CMake编译opencv(4.3)+contrib(4.3),以及相关问题解决

有关OpenCv在windows下的编译网上教程纷杂,但在我研究的过程中发现如果只是编译OpenCv本身的话还好,一旦添加Contrib之后就会有各种稀奇古怪的问题出现,在这里出一版经过本人研究确定可行的方案,以及相关的问题的解决


工具准备

Qt
  • 这里就放一个Qt的下载Link,Mingw使用Qt自带的版本就可以
    http://download.qt.io/archive/qt/
Cmake
OpenCv源码
OpenCv_Contrib源码
Note:OpenCv与OpenCv_Contrib的版本一定要保持一致

编译过程

  • 安装Qt
  • 安装CMake
Note:Qt与cmkae的安装较为简单,点击安装包直接安装即可,需要注意的是Qt安装的时候选择Mingw编译套件
  • 安装完毕后将CMake以及Mingw的安装路径添加到系统路径中
    sys path配置
  • 将OpenCv源码以及OpenCv_Contrib源码解压至同一个文件夹,我这里用的都是当前最新的4.3版本
    解压源码
  • 新建一个自己的build文件夹
    新建build文件夹
  • 启动CMake的GUI
    启动cmake
  • Browse Source选择OpenCv4.3
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uLMJPhjJ-1618910664403)(https://upload-images.jianshu.io/upload_images/19406162-1f8587412504f8bc.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
  • Browse Build选择新建好的编译文件夹
    选择编译文件夹
  • 点击Configure,选择MinGW Makefiles以及Specify native compliers,点击Next
    配置MinGW编译
  • 选择gcc以及g++的编译器的位置,然后选择Finish即可
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7FBrko2c-1618910664405)(https://upload-images.jianshu.io/upload_images/19406162-77f9c9070e9f64a8.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
Note:前面我们以及安装过Qt,编译器在安装路径的...Tools\mingw730_64\bin下
  • 等待Configure完成
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-B21KDxOs-1618910664405)(https://upload-images.jianshu.io/upload_images/19406162-54f5ac7150c61c56.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
    Configure完成
  • Search中搜索OPENCV_ENABLE_ALLOCATOR_STATS取消选中,搜索BUILD_opencv_world选中,重新Configure
    OPENCV_ENABLE_ALLOCATOR_STATS取消选中
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vVLOzzPQ-1618910664406)(https://upload-images.jianshu.io/upload_images/19406162-011d3c0a70fd1172.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
    再次configure
  • 点击Generate进行Makefile的生成
    Generate
  • 以管理员权限打开命令行并跳转到新建文件夹,执行命令mingw32-make -j8
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bU6hdQtO-1618910664407)(https://upload-images.jianshu.io/upload_images/19406162-5a012d3b4031bb26.PNG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
    开始编译
  • 编译完毕,执行mingw32-make install
    编译成功
    执行install
  • install完毕后即可在编译文件夹下的此路径...\build_opencv\Asa_build\install\x64\mingw\bin找到编译好的lib文件,include文件在编译文件夹下的...\install中,将include以及lib提出来便是编译好的完整的库文件以及包含文件了

过程中的问题

缺失ffmpeg.dll ffmpeg_64.dll文件
  • 下载链接https://github.com/AsaBoring/opencv_ffmpeg_file,将下载好的文件放在opencv-4.3.0/3rdparty/ffmpeg路径下
boostdesc_bgm.i: No such file or directory没有boostdesc_bgm等文件
  • 从这里下载boostdesc_bgm.i等文件的压缩包后将文件解压至opencv_contrib-4.3/modules/xfeatures2d/src中即可
features2d/test/test_detectors_regression.impl.hpp: 没有那个文件或目录
  • 1.将opencv-4.3/modules/features2d/test/文件夹下的
    test_descriptors_regression.impl.hpp
    test_detectors_regression.impl.hpp
    test/test_detectors_invariance.impl.hpp
    test_descriptors_invariance.impl.hpp
    test_invariance_utils.hpp
    拷贝到opencv_contrib-4.3/modules/xfeatures2d/test/路径下
  • 2将opencv_contrib-4.3/modules/xfeatures2d/test/test_features2d.cpp文件中的代码:
    #include features2d/test/test_detectors_regression.impl.hpp
    #include features2d/test/test_descriptors_regression.impl.hpp
    改为:
    #include "test_detectors_regression.impl.hpp"
    #include "test_descriptors_regression.impl.hpp"
  • 3将opencv_contrib-4.3/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp文件中的代码:
    #include "features2d/test/test_detectors_invariance.impl.hpp"
    #include "features2d/test/test_descriptors_invariance.impl.hpp"改为:
    #include "test_detectors_invariance.impl.hpp"
    #include "test_descriptors_invariance.impl.hpp"

库文件链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值