Repository navigation
Expand file tree
/
Copy pathFocusEffects.cpp
More file actions
94 lines (78 loc) · 2.39 KB
/
Copy pathFocusEffects.cpp
File metadata and controls
94 lines (78 loc) · 2.39 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
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "FocusEffects.h"
FocusEffects::FocusEffects(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.loadImage, SIGNAL(clicked()), this, SLOT(loadImage_clicked()));
connect(ui.processButton, SIGNAL(clicked()), this, SLOT(processButton_clicked()));
connect(ui.addSelectionButton, SIGNAL(clicked()), this, SLOT(addSelectionButton_clicked()));
connect(ui.subSelectionButton, SIGNAL(clicked()), this, SLOT(subSelectionButton_clicked()));
connect(ui.blurButton, SIGNAL(clicked()), this, SLOT(blurButton_clicked()));
connect(ui.imageArea, SIGNAL(clicked(QMouseEvent *)), this, SLOT(imageArea_clicked(QMouseEvent *)));
}
void FocusEffects::loadImage_clicked()
{
filename = QFileDialog::getOpenFileName(this, "Load an image", QDir::currentPath(), "Images (*.jpg *.jpeg *.png)");
if (filename.size())
{
ui.imageArea->setImage(filename);
}
}
void FocusEffects::processButton_clicked()
{
if (timesClicked == 2)
{
DNN::getInstance().setImage(filename.toStdString());
DNN::getInstance().processImage(cv::Rect(point1.x(), point1.y(), point2.x() - point1.x(), point2.y() - point1.y()));
cv::Mat proccesedImage = showSelection(DNN::getInstance().image, DNN::getInstance().combinedMask);
ui.imageArea->setImage(proccesedImage);
timesClicked = 0;
}
}
void FocusEffects::addSelectionButton_clicked()
{
clickType = 1;
}
void FocusEffects::subSelectionButton_clicked()
{
clickType = 2;
}
void FocusEffects::blurButton_clicked()
{
cv::Mat img = imread(filename.toStdString(), IMREAD_COLOR);
ui.imageArea->setImage(applyMask(img, DNN::getInstance().combinedMask, 5));
}
void FocusEffects::imageArea_clicked(QMouseEvent* ev)
{
switch (clickType)
{
case 0:
{
if (timesClicked == 0)
point1 = ev->pos();
else
if (timesClicked == 1)
point2 = ev->pos();
timesClicked++;
break;
}
case 1:
{
cv::Point p(ev->x(), ev->y());
addSelection(p, DNN::getInstance().combinedMask, DNN::getInstance().image);
cv::Mat proccesedImage = showSelection(DNN::getInstance().image, DNN::getInstance().combinedMask);
ui.imageArea->setImage(proccesedImage);
break;
}
case 2:
{
cv::Point p(ev->x(), ev->y());
subSelection(p, DNN::getInstance().combinedMask, DNN::getInstance().image);
cv::Mat proccesedImage = showSelection(DNN::getInstance().image, DNN::getInstance().combinedMask);
ui.imageArea->setImage(proccesedImage);
break;
}
default:
{break; }
}
}