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 }

 

posted @ 2024-08-22 20:45  莫莫大人  阅读(15)  评论(0编辑  收藏  举报