opencv条码(4)图像的flip之图形化界面

flip函数可以实现图像反转

这里贴出mainwindow.cpp的内容吧,书上的代码对应opencv2.2现在有些不能用了请注意

 

#include "mainwindow.h"
#include "ui_mainwindow.h"

using namespace cv;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->pushButton_2->setEnabled(false);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()    //button 1
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"),
                                                    ".", tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
    image = imread(fileName.toLatin1().data());
    if(image.data){
        ui->pushButton_2->setEnabled(true);
    }
    namedWindow("Original Image");
    imshow("Original Image", image);
}


void MainWindow::on_pushButton_2_clicked()    //button 2
{
    flip(image, image, 1);
 // cvtColor(image, image, CV_RGB2BGR);  cvtColor和CV_RGB2BGR现在用不了了~
    QImage img = QImage((const unsigned char*)(image.data), image.cols, image.rows, QImage::Format_RGB888);
    ui->label->setPixmap(QPixmap::fromImage(img));
    ui->label->resize(ui->label->pixmap()->size());
 // namedWindow("Output Image");
 // imshow("Output Image", image);
}

  

posted @ 2013-04-30 11:35  ChrisZZ  阅读(531)  评论(0编辑  收藏  举报