Qt5.14.2 MinGW7.3.0_64 opencv helloworld
路径配置.pro
INCLUDEPATH += E:\Opencv\include
LIBS += E:\Opencv\x64\mingw\lib\libopencv_*.a
点击按钮打开一张图片
1 #include "mainwindow.h" 2 #include "ui_mainwindow.h" 3 #include <QFileDialog> 4 #include <QMessageBox> 5 #include <QPixmap> 6 7 #include <opencv2/opencv.hpp> 8 #include <opencv2/imgproc.hpp> 9 10 using namespace cv; // 引入opencv的命名空间 11 using namespace std; 12 13 MainWindow::MainWindow(QWidget *parent) 14 : QMainWindow(parent) 15 , ui(new Ui::MainWindow) 16 { 17 ui->setupUi(this); 18 } 19 20 MainWindow::~MainWindow() 21 { 22 delete ui; 23 } 24 25 26 void MainWindow::on_pushButton_clicked() 27 { 28 29 QString filename = QFileDialog::getOpenFileName(this, "打开图像文件", "C:/Users", "Image Files (*.bmp;*.png;*.jpg)"); 30 31 if (filename.isEmpty()) { 32 QMessageBox::information(this, "提示", "文件打开失败1!"); 33 return; 34 } 35 Mat img_input; 36 img_input = cv::imread(filename.toLocal8Bit().toStdString()); 37 38 if (img_input.empty()) { 39 40 QMessageBox::information(this, "提示", "文件打开失败2!"); 41 return; 42 } 43 cv::Mat temp; 44 cv::cvtColor(img_input, temp, cv::COLOR_BGR2RGB); 45 46 namedWindow("Display window",WINDOW_AUTOSIZE); 47 imshow("Display window",img_input); 48 waitKey(0); 49 50 MainWindow w; 51 w.show(); 52 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】