-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
83 lines (67 loc) · 1.87 KB
/
mainwindow.cpp
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
80
81
82
83
#include <QtWidgets>
#include <functional>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "algorithms.h"
#include "refedges.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, 8, 13));
break;
case 6:
display(refEdges (original, grayscale, 1, 8, 13, 1, 1, 5, 7, 0.5));
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));
}