#include "dialog.h"
#include "ui_dialog.h"
#include "qfiledialog.h"
#include "qdebug.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pBtnLoadImage_clicked()
{
QString file = QFileDialog::getOpenFileName(this,"Open Image",".","Image Files(*.png *.jpg *.jpeg *.bmp);;All Files(*)");
if(!file.isNull())
{
qDebug()<<file;
image = cv::imread(file.toStdString());
cv::imshow("Original",image);
}
}
void Dialog::on_pBtnFlip_clicked()
{
static int flag=1;
flag=flag>0?0:1;
qDebug()<<"flag="<<flag;
cv::flip(image,image,flag);
cv::imshow("Output Image",image);
}
第二种界面:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qfiledialog.h"
#include "qdebug.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pBtnLoadImage_clicked()
{
QString file = QFileDialog::getOpenFileName(this,"OPen Image",".","Image file(*.jpg *.png *.bmp);;All files(*)");
if(!file.isNull())
{
image = cv::imread(file.toStdString());
cv::cvtColor(image,image,CV_BGR2RGB);
qDebug()<<"Image"<<image.depth();
ShowImage();
}
}
void MainWindow::on_pBtnFlip_clicked()
{
static int flag=1;
cv::flip(image,image,flag);
flag = flag>0 ? 0 : 1;
ShowImage();
}
void MainWindow::ShowImage()
{
QImage img=QImage(image.data,image.cols,image.rows,QImage::Format_RGB888);
ui->lbShowImage->setPixmap(QPixmap::fromImage(img));
ui->lbShowImage->resize(img.size());
}