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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kidults/article/details/84334351

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

环境

win10 64位
Qt 5.7  (MinGW 5.3.0 32 bit)  
opencv-3.4.1

下载编译工具cmake和源码

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

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

编译

  1. cmake初始界面

在这里插入图片描述

2.选择编译的目标路径和源码路径
在这里插入图片描述
3.选择编译器
在这里插入图片描述
4. 指定生成器
要注意和Qt的版本匹配
在这里插入图片描述
5. 点击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)
/*************************************************************************************************************************/
  
  1. 勾选 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:

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

  方法: 添加配置    CMAKE_PREFIX_PATH      D:\QtCreator\5.5\mingw492_32\lib\cmake    
  /*************************************************************************************************************************/ 
  1. 点击Generate
    在这里插入图片描述
  2. 在命令行进入刚才的目标路径
    执行 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 <ctime>
#include <cstdlib>

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

猜你喜欢

转载自blog.csdn.net/kidults/article/details/84334351