QT编译opencv

一.QT5.12编译

1.QT环境

QT5.12

Qt Creator 12.0.2

2.OpenCV文件

因为QT5.12版本qt最后支持到2021.12月,所以这里选择的opencv版本为2021.4月发布的opencv-3.4.16版本

官网下载地址:https://opencv.org/releases/

最新版本:opencv-3.4.16.zip

3.用Qt Creator 12.0.2打开opencv工程(cmakelist.txt)

(1)构建

(2)构建成功后,在build-opencv-3.4.16-Desktop_Qt_5_12_10_MinGW_64_bit-Release中打开cmd窗口,执行cmake打包语句:

cmake -P cmake_install.cmake ,然后会在同目录下生成instll文件夹,文件夹内会有dll及.h文件。

二.QT6.7编译

1.QT环境

QT6.7

Qt Creator 12.0.2

2.OpenCV文件

官网下载地址:https://opencv.org/releases/

最新版本:opencv-4.10.0.zip

3.用Qt Creator 12.0.2打开opencv工程(cmakelist.txt)

(1)构建

(2)构建成功后,在build-opencv-4.10.0-Desktop_Qt_6_7_0_MinGW_64_bit-Release中打开cmd窗口,执行cmake打包语句:

cmake -P cmake_install.cmake ,然后会在同目录下生成instll文件夹,文件夹内会有dll及.h文件。

三.opencv显示图片测试示例

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/opencv.hpp>

#include <QImage>

#include <QPixmap>

#include <QLabel>

using namespace cv;

int main(int argc, char *argv\[\])

{

QApplication a(argc, argv);

cv::Mat image = cv::imread("D:/OpenCV_app/test.jpg");

if(image.empty()) return -1;

cv::Mat gray_image;

cvtColor( image, gray_image, cv::COLOR_BGR2GRAY );

imwrite( "Gray_Image.jpg", gray_image );

namedWindow( "D:/OpenCV_app/test.jpg", WINDOW_AUTOSIZE );

imshow( "D:/OpenCV_app/test.jpg", image );

namedWindow( "Gray image", WINDOW_AUTOSIZE );

imshow( "Gray image", gray_image );

return a.exec();

}

相关推荐
慧都产品智能化6 小时前
Qt 开发 CAD/CAM 工序表的隐性成本分析
c++·qt·qt5·qt6.3
ShineWinsu1 天前
对于Qt窗口:QMainWindow、QMenuBar、Qmenu、QAction的解析
c++·qt·菜单·qmainwindow·qaction·qmenu·qmenubar
ShineWinsu1 天前
对于Qt:QSpacerItem常见属性以及方法的解析
开发语言·c++·qt·面试·系统架构·客户端·qspaceritem
ShineWinsu1 天前
对于Qt:QGripLayout常见属性、方法以及QSizePolicy的解析
开发语言·c++·qt·面试·gui·客户端·网格
艾莉丝努力练剑1 天前
【QT】系统相关:TCP的API介绍
开发语言·前端·c++·人工智能·qt·学习·tcp/ip
ShineWinsu2 天前
对于Qt:QVBoxLayout常见属性以及方法的解析
开发语言·数据库·c++·qt·gui·客户端·布局管理器
ShineWinsu2 天前
对于Qt:QFormLayout常见属性以及方法的解析
开发语言·c++·qt·面试·客户端·表单·qformlayout
ShineWinsu3 天前
对于Qt:QHBoxLayout常见属性以及方法的解析
c++·qt·面试·gui·客户端·布局管理器·水平布局器
敲上瘾3 天前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3
Sakura_j_h_4 天前
MCP SDK 2.0 实战:用 MCPServer 搭本地笔记检索服务
开发语言·笔记·python·qt·ai工具·mcp·mcpserver