Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | PointedEar | 1 | /*------------------------------------------------------------------------------------------*\ |
2 | This file contains material supporting chapter 1 of the cookbook: |
||
3 | Computer Vision Programming using the OpenCV Library. |
||
4 | by Robert Laganiere, Packt Publishing, 2011. |
||
5 | |||
6 | This program is free software; permission is hereby granted to use, copy, modify, |
||
7 | and distribute this source code, or portions thereof, for any purpose, without fee, |
||
8 | subject to the restriction that the copyright notice may not be removed |
||
9 | or altered from any source or altered source distribution. |
||
10 | The software is released on an as-is basis and without any warranties of any kind. |
||
11 | In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
||
12 | The author disclaims all warranties with regard to this software, any use, |
||
13 | and any consequent failure, is purely the responsibility of the user. |
||
14 | |||
15 | Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
||
16 | \*------------------------------------------------------------------------------------------*/ |
||
17 | #include "mainwindow.h" |
||
18 | #include "ui_mainwindow.h" |
||
19 | |||
20 | MainWindow::MainWindow(QWidget *parent) |
||
21 | : QMainWindow(parent), ui(new Ui::MainWindow) |
||
22 | { |
||
23 | ui->setupUi(this); |
||
24 | ui->pushButton_2->setEnabled(false); |
||
25 | } |
||
26 | |||
27 | MainWindow::~MainWindow() |
||
28 | { |
||
29 | delete ui; |
||
30 | } |
||
31 | |||
32 | void MainWindow::on_pushButton_clicked() |
||
33 | { |
||
34 | QString fileName = QFileDialog::getOpenFileName(this, |
||
35 | tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.bmp)")); |
||
36 | |||
37 | image= cv::imread(fileName.toAscii().data()); |
||
38 | |||
39 | if (image.data) { |
||
40 | cv::namedWindow("Original Image"); |
||
41 | cv::imshow("Original Image", image); |
||
42 | ui->pushButton_2->setEnabled(true); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | void MainWindow::on_pushButton_2_clicked() |
||
47 | { |
||
48 | cv::flip(image,image,1); // process the image |
||
49 | |||
50 | cv::cvtColor(image,image,CV_BGR2RGB); // change color channel ordering |
||
51 | QImage img= QImage((const unsigned char*)(image.data), // Qt image structure |
||
52 | image.cols,image.rows,QImage::Format_RGB888); |
||
53 | ui->label->setPixmap(QPixmap::fromImage(img)); // display on label |
||
54 | ui->label->resize(ui->label->pixmap()->size()); // resize the label to fit the image |
||
55 | } |