window 下使用opencv 且opencv支持QT

软件环境
Qt-5.9.3(mingw530)
MinGW-5.1.0-32bit(下载的QT里面有)
CMake-3.11.3
OpenCV-2.4.9

1 编译opencv WITH_QT 
  官网上下载下来编译好的opencv,不支持QT
  因此需要自己编译
 
2 下载的 OpenCV 文件夹会有:
  build (已编译好的库,使用 MSVC 的话,直接在)
  sources (源码)
  QT使用的是MinGW 版,因此需要自己编译,
  MinGW 版的opencv(支持QT)编译流程
 (1)CMake 自行安装
 (2)MinGW 可以直接使用qt里面的

  打开 cmake-gui,设置源码和生成路径:
  Where is the source code: E:/OpenCV_2.4.9/opencv/sources
  Where to build the binaries:
E:/OpenCV_2.4.9/opencv-build(名字随便,不要与已有的build重合就行)
 
  点击 Configure,设置编译器
  Specify the generator for this project: MinGW Makefiles
  Specify native compilers
  Next
  Compilers C: E:\Qt\Qt5.9.3\Tools\mingw530_32\bin\gcc.exe
  Compilers C++: E:\Qt\Qt5.9.3\Tools\mingw530_32\bin\g++.exe
  Finish
  
  此时出现一系列红色,
    勾选 WITH_QT
    勾选 WITH_OPENGL
    不勾选 WITH_IPP
 
  再次点击 Configure,出现下列设置选项
  设置 QT_MAKE_EXECUTABLE 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\bin\qmake.exe
  设置 Qt5Concurrent_DIR 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\cmake\Qt5Concurrent
  设置 Qt5Core_DIR 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\cmake\Qt5Core
  设置 Qt5Gui_DIR 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\cmake\Qt5Gui 0
  设置 Qt5Test_DIR 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\cmake\Qt5Test
  设置 Qt5Widgets_DIR 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\cmake\Qt5Widgets
  设置 Qt5OpenGL_DIR 为 E:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\cmake\Qt5OpenGL

  点击 Generate 生成 Makefile

  **编译 OpenCV**
  进入到你之前设置的目录(E:/OpenCV_2.4.9/opencv-build)
  直接运行 E:\Qt\Qt5.9.3\Tools\mingw530_32\bin\mingw32-make
  (最好设置E:\Qt\Qt5.9.3\Tools\mingw530_32\bin 为系统变量)
  如果编译有问题,自行百度,我是一气呵成的

  编译好了进行安装
  运行 mingw32-make install
  
  最好大功完成
  G:\paper\opencv249\build\install\x64\mingw\bin 下生成*249.dll
  G:\paper\opencv249\build\install\x64\mingw\lib  下生成*249.dll.a

  G:\paper\opencv249\build\install\x64\mingw\bin 设置到系统变量里面
  
3  QT使用编译好的opencv
   .po 文件中设置
    INCLUDEPATH += G:\paper\opencv249\build\install\include
    INCLUDEPATH += G:\paper\opencv249\build\install\include\opencv
    INCLUDEPATH += G:\paper\opencv249\build\install\include\opencv2

LIBS +=G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_core249.dll.a\

      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_calib3d249.dll.a\

      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_contrib249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_core249.dll.a\

      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_features2d249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_flann249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_gpu249.dll.a\

      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_highgui249.dll.a\

      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_imgproc249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_legacy249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_ml249.dll.a\

      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_objdetect249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_video249.dll.a\
      G:\paper\opencv249\build\install\x64\mingw\lib\libopencv_ocl249.dll.a

main文件:
#include "opencv2/opencv.hpp"
const std::string input_file_name = "input.png";
cv::Mat image = imread(input_file_name);

如果出现
G:\01miwork\qtpro2\bandTest\main.cpp:11: error: undefined reference to
`cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&,

.po 文件中设置
DEFINES += _GLIBCXX_USE_CXX11_ABI=0

记得重新构建
  

  
  
   
   

技术
©2019-2020 Toolsou All rights reserved,
项目跟了一年,客户最后说不做了 云计算的最大安全风险:安全责任不清ELementUI select多选下拉框获取选中项的全部属性Result返回结果信息的封装(精华)2020年8月15日 redis数据库 StackExchange.Redis中Set类型(C#版)明明是post请求为什么会在地址栏显示参数?人工智能算法总结常见的5种JAVA运行时异常element-ui+vue-treeselect下拉框的校验Dijkstra算法的Python实现-最短路径问题