QT内label控件通过opencv显示图像

时间:2022-02-08 18:00:51

1.对pro进行配置。使其可以理解opencv。

INCLUDEPATH+=d:\opencv249\include\opencv\
d:\opencv249\include\opencv2\
d:\opencv249\include LIBS+=d:\opencv249\lib\libopencv_calib3d249.dll.a\
d:\opencv249\lib\libopencv_contrib249.dll.a\
d:\opencv249\lib\libopencv_core249.dll.a\
d:\opencv249\lib\libopencv_features2d249.dll.a\
d:\opencv249\lib\libopencv_flann249.dll.a\
d:\opencv249\lib\libopencv_gpu249.dll.a\
d:\opencv249\lib\libopencv_highgui249.dll.a\
d:\opencv249\lib\libopencv_imgproc249.dll.a\
d:\opencv249\lib\libopencv_legacy249.dll.a\
d:\opencv249\lib\libopencv_ml249.dll.a\
d:\opencv249\lib\libopencv_objdetect249.dll.a\
d:\opencv249\lib\libopencv_video249.dll.a

2.在*.ui内创建两个命令button。一个标签。其界面为:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoYAAAH2CAYAAADtQE0lAAAgAElEQVR4Ae3df7AlVYEf8DMMg4V/hEHQxVgmDr/8WWarTK3WbimM4oIgK1UpdHVZB0EW5aeKJhsUAUFwa6MIuOoGlIG4a9zSBEVBEgWMpaWpbFW0VJCBGbawxESNzB9hJcC83HOH09Pdr+99/Q533n3v9OeWb/rXOaf7fM6p65fb791eF8LCQqi9Hv1/j9e2rE4SWL9+/aRD9hMgsAYE9l2/rvMqH3+i8ZbYWcZOAgQIrHWBSe+B6xZGr9i5//vIo2u9jyt6/Rs2bFjR8zkZAQIECBAgQGCWAuv3WRc+97mbwpYtW6pm901rjz3+RFq17CGwz/qKrkdpRQgQIECAAAECq0tgXceNkyrd/Pa3j62uq13tV7OuolvtV+r6CBAgQIAAAQKLBNbtt/jX4qp08+hjfrdwkdiUHfvu5/eQpvA4RIAAAQIECKxygV3NPzMZX20VDB9bVjC8N1x77BkhXPutcO6RE3p9778Lx58bwtW3vzccUSuy7eqjwvHb3hu2feLE2t7dq7edc0g472uLdjd3nHDdnr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Y137UoF4bKlXu716+Wlt18vtjfU+157OO60Pscw8+5Gu0ZIAAQJRQDA0DwgQmJlADEDtkNO1r37Cemhq150WvlLZtKy3mdan1U9l6ueP+6bVaZetb0+6jnZ7k8ql67EkQIDAPAUEw3nqOzeBAgVSWOoKRKm7qUzaXu6yHq5iW/XtdlvTztW+xlh3Wvl222k7tZOWue2k9iwJECAwLwHBcF7yzkugcIGugNUV4OphKpK0t9tMXW1MC4dLtdduf7nbqf16f9O+5balPAECBOYtIBjOewScn0AhAvUwlEJS3JfWJ3Wzfrxdvt5mWo/l03q9zfr+epv19Xr5uF5vp77eLtferreZ1uv10752vbRdL9u1b6n6qY4lAQIEZi1Q/VXyvL5x23m7h5QLlyiwluZBDDPtQBO3YwiK/YjL9vHuUe7eW29/69at47bSvtRu2q63EM876SeVi9eX6taX8Xh9O5031au3Wy9X35/K1pepbGovbadlvWxcX0vzoH3t9W39qGvsWeeyx6K+xqWusWd91i57Wt69tm5h9IqrO3fubB+zTYAAgWULxFAUA0791bUvHo/7l3q121qqfNfx9vnb21114r5p5drH4nZ8ta+3q1y7zLiifwgQIDAHgRg0608+cSt5DoPglASGJJCCUVrW+94OSF1lUvl4rO8rtjutrXo77XLt7VR20v50PPVlqXKxfCzT9UptdB2zjwABAishIBiuhLJzEBioQD0kdYW1roDU3pfCUlpGynq7k2i7ztcu26edVGdae+maY5n6daa67WVXmdRGu6xtAgQIrKSAYLiS2s5FYEACXaGrHa7aAamrTptsUpmu/el87Tbidlf5rn31uqm99nWn7Vg/vtJ2vW5cX6r9dnnbBAgQWGkBwXClxZ2PQMECKfikZVdXJ4WmrrLtfSl4pWXX8Xb7cburfLvctGtunydtd7Ubj03an+pZEiBAYLUKCIardWRcF4E1JlAPVpPCWOrStONdoSqFuLRM7bSX9br19Vhu2nZst912u3w6V71cfT0dby9TO3HZp3y7vm0CBAispIBguJLazkWgYIF26Glvt7u+1PF2+T7b9Tbr633qtsssVX+p46m9VC4t0/72cqnj7fK2CRAgsDcEqu8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XafyIvtG4sF6egQwQIEBgLrBv/h/Li/1pu/nINLAIECJQpMOk90B+flDneekWAAAECBAgQWLbA6FZy7QPDZVdXgQABAmtZwPvfWh49106AwFMVWPwe+P8BT2CVpqTHia4AAAAASUVORK5CYII=" alt="" />

3.配置其.h文件、.cpp文件。

.h文件:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
cv::Mat image;
QImage img; private slots:
void on_pushButton_clicked(); void on_pushButton_2_clicked(); private:
Ui::MainWindow *ui;
}; #endif // MAINWINDOW_H

.cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>
#include <QFileDialog>
#include <QMessageBox>
#include <opencv/cv.h>
#include <QTextCodec>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::on_pushButton_clicked()
{
QString filename = QFileDialog::getOpenFileName(this,tr("Open Image"),"",tr("Image File(*.bmp *.jpg *.jpeg *.png)"));
QTextCodec *code = QTextCodec::codecForName("gb18030");
std::string name = code->fromUnicode(filename).data();
image = cv::imread(name);
if(!image.data)
{
QMessageBox msgBox;
msgBox.setText(tr("image data is null"));
msgBox.exec();
}
else
{
cv::cvtColor(image,image,CV_BGR2RGB);
img = QImage((const unsigned char*)(image.data),image.cols,image.rows, image.cols*image.channels(), QImage::Format_RGB888);
ui->label->clear();
ui->label->setPixmap(QPixmap::fromImage(img));
//ui->processPushButton->setEnabled(true);
ui->label->resize(ui->label->pixmap()->size());
}
} void MainWindow::on_pushButton_2_clicked()
{
cv::flip(image,image,1);
img = QImage((const unsigned char*)(image.data),image.cols,image.rows,image.cols*image.channels(), QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(img));
}

补充:

image.cols*image.channels()

可以改为image.step.

參考资料:

1.使用Qt显示openCV矩阵图片    http://blog.csdn.net/homechao/article/details/8989641

2. Qt中用QLabel显示OpenCV中Mat图像数据出现扭曲现象的解决    http://lovelittlebean.blog.163.com/blog/static/11658218620125208212189/