事先采用MinGW编译好的OpenCV4.0.1
https://github.com/huihut/OpenCV-MinGW-Build
在pro文件中加入 头文件路径和库路径
INCLUDEPATH +=D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\include
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_calib3d411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_core411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_dnn411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_features2d411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_flann411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_gapi411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_highgui411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_imgcodecs411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_imgproc411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_ml411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_objdetect411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_photo411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_stitching411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_video411.dll
LIBS += D:\OpenCV-MinGW-Build-OpenCV-4.1.1-x64\x64\mingw\bin\libopencv_videoio411.dll
加入opencv相关头文件 (函数的引用)
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
显示一个图片代码如下 Mat src = cv::imread("F:/Qt_demo_byown/FFmpegDemo/1.jpg",1); Mat img; cvtColor(src, img, COLOR_BGR2RGB); ui->label->setPixmap(QPixmap::fromImage(QImage(img.data, img.cols, img.rows, img.step, QImage::Format_RGB888)));
记得发布程序的时候需要把 dll文件 和exe文件拷贝到发布路径
大部分参考https://blog.csdn.net/qq_33474442/article/details/87074218
来源:CSDN
作者:m0_37056522
链接:https://blog.csdn.net/m0_37056522/article/details/103890556