-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
237 lines (200 loc) · 6.34 KB
/
mainwindow.cpp
File metadata and controls
237 lines (200 loc) · 6.34 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "vars.hpp"
#include <QMessageBox>
#include <QSpinBox>
#include <QVector>
#include <algorithm>
#include <QScreen>
using namespace cv;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
MainWindowStyleSheet();
ui->setupUi(this);
SpinBoxInit();
KernelTypeCheck();
}
MainWindow::~MainWindow()
{
delete ui;
}
//TODO: error handling for null/empty file
void MainWindow::on_loadimage_clicked()
{
QString l_fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
//m_image = cv::imread(fileName.toStdString());
//change opencv BGR to RGB
//cv::cvtColor(m_image, m_image, COLOR_BGR2RGB);
QRect l_screenGeometry = GetScreenSize();
int l_screenWidth = l_screenGeometry.width();
int l_screenHeight = l_screenGeometry.height();
QPixmap l_media(l_fileName);
int l_mediaWidth = l_media.width();
int l_mediaHeight = l_media.height();
if ((l_mediaWidth > l_screenWidth) || (l_mediaHeight > l_screenHeight))
{
//change size variables to be used in scaling of image
l_mediaWidth = l_screenWidth - 292;
l_mediaHeight = l_screenHeight - 30;
\
//if this is a huge image, does it need to be copied to show a smaller version of it while the kernel goes over the actual image?
//scale everything down
l_media.scaled(l_mediaWidth, l_mediaHeight);
ui->imgbox->resize(l_screenWidth, l_screenHeight);
MainWindow::resize(l_screenWidth, l_screenHeight);
ui->imgbox->setPixmap(l_media);
} else
{
ui->imgbox->resize(l_media.size());
MainWindow::resize(l_media.width() + 292, l_media.height() + 30);
ui->imgbox->setPixmap(l_media);
}
//cv::namedWindow("Original Image");
//cv::imshow("Original Image", m_image);
}
void MainWindow::on_applykernel_clicked()
{
//TODO:
//Conversion from opencv BGR to RGB or vice-versa
//Convert QVector Kernel_Gather_Values() to OpenCV::Mat - needed?
//Apply kernel to img
//display image again in label(conversion might be needed again)
// -"Destructive" vs applying to Copy
//TODO:
//make this into separate thread
//can add progress bar when applying kernel on large image - signal and slot business
}
void MainWindow::MainWindowStyleSheet()
{
//test stylesheet stuff
MainWindow::setStyleSheet("background-color: yellow");
}
//set
void MainWindow::SpinBoxInit()
{
for (auto i : findChildren<QSpinBox*>())
i->setMinimum(-256);
ui->stackedWidget->setCurrentIndex(1);
for (auto i : findChildren<QSpinBox*>())
i->setMinimum(-256);
ui->stackedWidget->setCurrentIndex(0);
//set start up kernel as Identity
ui->spinBox4->setValue(1);
}
//get all values in spinboxes in the UI, store in QVector, return QVector.
QVector<int> MainWindow::Kernel_Gather_Values_3X3()
{
//iterative approach won't work with:
//ui->stackedWidget->currentWidget()->findChildren<QSpinBox*>()??
//gathers and sets wrong values
QVector<int> l_spinboxvalues;
l_spinboxvalues.push_back(ui->spinBox0->value());
l_spinboxvalues.push_back(ui->spinBox1->value());
l_spinboxvalues.push_back(ui->spinBox2->value());
l_spinboxvalues.push_back(ui->spinBox3->value());
l_spinboxvalues.push_back(ui->spinBox4->value());
l_spinboxvalues.push_back(ui->spinBox5->value());
l_spinboxvalues.push_back(ui->spinBox6->value());
l_spinboxvalues.push_back(ui->spinBox7->value());
l_spinboxvalues.push_back(ui->spinBox8->value());
return l_spinboxvalues;
}
void MainWindow::SetSpinBoxKernel(const QVector<int> a_kernel)
{
//does not get the right values
// int j = 0;
// for (auto i : ui->stackedWidget->currentWidget()->findChildren<QSpinBox*>())
// {
// i->setValue(a_kernel[j++]);
// }
//gets ALL spin boxes, page 1 and page 2
// int j = 0;
// for (auto i : ui->stackedWidget->indexOf())
// {
// i->setValue(a_kernel[j++]);
// }
ui->spinBox0->setValue(a_kernel[0]);
ui->spinBox1->setValue(a_kernel[1]);
ui->spinBox2->setValue(a_kernel[2]);
ui->spinBox3->setValue(a_kernel[3]);
ui->spinBox4->setValue(a_kernel[4]);
ui->spinBox5->setValue(a_kernel[5]);
ui->spinBox6->setValue(a_kernel[6]);
ui->spinBox7->setValue(a_kernel[7]);
ui->spinBox8->setValue(a_kernel[8]);
}
QRect MainWindow::GetScreenSize()
{
//get user's screen size scalability
QList<QScreen*> l_totalScreensNumber = QApplication::screens();
QScreen* l_firstscreen = l_totalScreensNumber.first();
QRect l_screenGeometry = l_firstscreen->geometry();
return l_screenGeometry;
}
//gets all values in spinboxes
//iterates through all pre-set kernels
//if kernel exists, change label to tell user what it is
void MainWindow::KernelTypeCheck()
{
QVector<int> l_kernel = Kernel_Gather_Values_3X3();
QString l_returnString = "";
for (int i = 0; i < VK_KERNELS.length(); i++)
{
if (std::equal(VK_KERNELS[i].begin(), VK_KERNELS[i].end(), l_kernel.begin()))
{
l_returnString = VK_KERNEL_NAMES[i];
}
}
ui->label_2->setText(l_returnString);
}
void MainWindow::on_actionIdentity_triggered()
{
SetSpinBoxKernel(VK_IDENTITY);
KernelTypeCheck();
}
void MainWindow::on_actionSharpen_triggered()
{
SetSpinBoxKernel(VK_SHARPEN);
KernelTypeCheck();
}
void MainWindow::on_actionEdge_Detect_1_triggered()
{
SetSpinBoxKernel(VK_EDGE_DETECT1);
KernelTypeCheck();
}
void MainWindow::on_actionEdge_Detect_2_triggered()
{
SetSpinBoxKernel(VK_EDGE_DETECT2);
KernelTypeCheck();
}
void MainWindow::on_actionEdge_Detect_3_triggered()
{
SetSpinBoxKernel(VK_EDGE_DETECT3);
KernelTypeCheck();
}
void MainWindow::on_actionBox_Blur_triggered()
{
SetSpinBoxKernel(VK_BOX_BLUR);
KernelTypeCheck();
}
void MainWindow::on_actionGaussian_Blur_3x3_triggered()
{
SetSpinBoxKernel(VK_GAUSSIAN_BLUR_3X3);
KernelTypeCheck();
}
void MainWindow::on_action5x5_triggered()
{
ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::on_action3x3_triggered()
{
ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::on_actionGaussian_Blur_5x5_triggered()
{
if (!ui->stackedWidget->currentIndex())
ui->stackedWidget->setCurrentIndex(1);
//apply 5x5 kernel
}