windows平台 Qt环境 opencv源码的编译

男娘i 2022-04-15 05:35 645阅读 0赞

最近在做人脸识别,opencv作为一款开源的人脸识别库,最基本的使用还是可以的

环境

  1. win10 64
  2. Qt 5.7 (MinGW 5.3.0 32 bit)
  3. opencv-3.4.1

下载编译工具cmake和源码

Qt要使用opencv,首先得下载opencv源码,进行编译,编译工具cmake
camke工具和opecv源码的下载地址
下载地址

如果不想编译,可直接下载使用

编译

  1. cmake初始界面

在这里插入图片描述

2.选择编译的目标路径和源码路径
在这里插入图片描述
3.选择编译器
在这里插入图片描述

  1. 指定生成器
    要注意和Qt的版本匹配
    在这里插入图片描述
  2. 点击Configure(一般会报错),直到界面无红色面无红色
    我在编译过程中出现的错误和解决方法

    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_MAKE_PROGRAM 项设置为camke路径: D:/CMake/bin/cmake.exe,重新点击Configure
    /*/

    cmake-gui 由于找不到libwinpthread-1.dll 无法继续执行代码

    方法:将qt的D:\QtCreator\Tools\mingw492_32\bin 路径加入到系统Path环境变量中。 并重启CMake (cmake-gui)
    /*/

  3. 勾选 WITH_QT 和 WITH_OPENGL 点击Configure

    勾选 WITH_QT WITH_OPENGL之后报错

    Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version “2.7”)
    Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version “2.6”)
    Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version “3.4”)
    Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version “3.2”)
    CMake Warning at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
    By not providing “FindQt5Core.cmake” in CMAKE_MODULE_PATH this project has
    asked CMake to find a package configuration file provided by “Qt5Core”, but
    CMake did not find one.

    Could not find a package configuration file provided by “Qt5Core” with any
    of the following names:

    1. Qt5CoreConfig.cmake
    2. qt5core-config.cmake
    3. 后面还有许多类似的错误

    方法: 添加配置 CMAKE_PREFIX_PATH D:\QtCreator\5.5\mingw492_32\lib\cmake
    /*/

  4. 点击Generate
    在这里插入图片描述

  5. 在命令行进入刚才的目标路径
    执行 mingw32-make

    过程中出现的问题
    1、error: ‘nullptr’ was not declared in this scope

    报错文件io_win32.cc
    nullptr是C++11引入的新特性,目前版本编译器不支持C++11。
    修改nullptr为NULL

    2、error: ‘else’ without a previous ‘if’error:’sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA’ was not declared inthis scope

    报错文件:cap_dshow.cpp
    缺少宏定义
    cap_dshow.cpp中添加如下宏定义:#define STRSAFE_NO_DEPRECATE

    3、error:’time’ was not declared in this scope
    报错文件:opencv-3.4.1\modules\photo\test\test_hdr.cpp
    缺少文件包含
    test_hdr.cpp前面增加头文件

    include

    include

  6. 执行 mingw32-make install

  7. 我们只需要目标路径的bin include lib三个文件夹
    在这里插入图片描述
    **
    opencv在Qt的使用 请点击

发表评论

表情:
评论列表 (有 0 条评论,645人围观)

还没有评论,来说两句吧...

相关阅读