-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
79 lines (63 loc) · 1.75 KB
/
Copy pathmainwindow.cpp
File metadata and controls
79 lines (63 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <QtWidgets>
#include <functional>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "algorithms.h"
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
filename = QFileDialog::getOpenFileName(this, tr("Select a single image"));
original = QImage(filename);
display(original);
grayscale = original.convertToFormat(QImage::Format_Grayscale8);
ui->comboBox->setCurrentIndex(0);
}
void MainWindow::display(const QImage& image) {
scene->clear();
scene->addPixmap(QPixmap::fromImage(image));
scene->setSceneRect(image.rect());
ui->image->setScene(scene);
ui->image->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
current = image;
}
void MainWindow::on_comboBox_currentIndexChanged(int index)
{
switch (index) {
case 0:
display(original);
break;
case 1:
display(canny(grayscale, 1, 40, 120));
break;
default:
function<QImage(const QImage&)> functions[] = {
sobel,
prewitt,
roberts,
scharr
};
display(functions[index - 2](grayscale));
break;
}
}
void MainWindow::resizeEvent(QResizeEvent* event) {
QMainWindow::resizeEvent(event);
ui->image->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
}
void MainWindow::on_pushButton_2_clicked()
{
auto path = QFileDialog::getExistingDirectory(this, tr("Destination"));
auto name = QString("%1_%2").arg(ui->comboBox->currentText(), QFileInfo(filename).fileName());
current.save(QDir(path).filePath(name));
}