This repository was archived by the owner on Apr 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
355 lines (275 loc) · 9.96 KB
/
mainwindow.cpp
File metadata and controls
355 lines (275 loc) · 9.96 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "camera.h"
#include "videoqlabel.h"
#include "video_dispatch.h"
#include "imageprocessor.h"
#include <QMainWindow>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QGroupBox>
#include <QPushButton>
#include <QMainWindow>
#include <QLabel>
#include <QHBoxLayout>
#include <QTabWidget>
#include <QAction>
#include <QMenuBar>
#include <QMenu>
#include <QWidget>
#include <QApplication>
#include <QFormLayout>
#include <QThread>
#include <QLineEdit>
#include <QTimer>
#include <QCloseEvent>
#include <QGridLayout>
#include <opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/objdetect/objdetect.hpp>
const int MainWindow::DEFAULT_FPS = 10;
#include "savefilethread.h"
#include <iostream>
// Constructor:
//*********************************************************************************************************************
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
createMenu();
// main layout:
QWidget *centralWidget = new QWidget(this);
QHBoxLayout *mainLayout = new QHBoxLayout;
centralWidget->setLayout(mainLayout);
// ui->setupUi(this);
// left box:
//**************************************************
QWidget *leftBox = new QWidget(centralWidget);
leftBox->setMinimumWidth(230);
// create tabPanel:
tabPanel = new QTabWidget(leftBox);
// create Calibration Tab:
createCalibrationTab(leftBox);
// create General Tab:
createGeneralTab(leftBox);
//right box:
//**************************************************
QWidget *rightBox = new QWidget;
// video box QLabel
VideoQLabel *videoBox = new VideoQLabel(rightBox);
videoBox->setActiveClick(true);
videoBox->setText("Video stream window");
QGridLayout *rightBoxLayout = new QGridLayout;
rightBoxLayout->addWidget(videoBox);
rightBox->setLayout(rightBoxLayout);
rightBox->setStyleSheet("background-color:#e9e9e9;");
// add boxes to main layout:
mainLayout->addWidget(leftBox,1);
mainLayout->addWidget(rightBox,3);
// set central widget of QMainWindow
setCentralWidget(centralWidget);
//cascade
mouthClassifier = new cv::CascadeClassifier("D:\\INTERFEJSY_MOUTH\\haarcascade_mcs_mouth.xml");
if(mouthClassifier->empty()){
throw "fuck";
}
faceClassifier = new cv::CascadeClassifier("D:\\INTERFEJSY_MOUTH\\haarcascade_frontalface_default.xml");
if(faceClassifier->empty()){
throw "fuck";
}
dispatcher = new VideoDispatcher();
dispatcher->attach(videoBox);
dispatcher->setPreprocessor(*new MouthClassifierProcessor(*faceClassifier,*mouthClassifier));
initiateTimer();
}
// Destructor:
//*********************************************************************************************************************
MainWindow::~MainWindow()
{
}
// USER INTERFACE:
//*********************************************************************************************************************
// Create Menu:
void MainWindow::createMenu(){
saveAction = new QAction("Save", this);
loadAction = new QAction("Load", this);
quitAction = new QAction("Quit", this);
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(loadAction, SIGNAL(triggered()), this, SLOT(load()));
connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));
QMenuBar *menuBar = new QMenuBar(this);
QMenu *menuFile = new QMenu("File",menuBar);
menuBar->addMenu(menuFile);
menuFile->addAction(saveAction);
menuFile->addAction(loadAction);
menuFile->addAction(quitAction);
setMenuBar(menuBar);
}
// Create Left Panel:
void MainWindow::createGeneralTab(QWidget *parent)
{
// create general page:
generalTab = new QWidget(parent);
QVBoxLayout *generalTabLayout = new QVBoxLayout();
generalTab->setLayout(generalTabLayout);
// create general page content:
//create algorithm box:
QGroupBox *algorithmBox = new QGroupBox("Algorithm:",generalTab);
startButton = new QPushButton("Start");
connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
stopButton = new QPushButton("End");
connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));
QFormLayout *formLayoutAlgorithm = new QFormLayout();
algorithmBox->setLayout(formLayoutAlgorithm);
formLayoutAlgorithm->addRow("Start algorithm:", startButton);
formLayoutAlgorithm->addRow("Stop algorithm:", stopButton);
// add algorithmBox to mainLayout
generalTabLayout->addWidget(algorithmBox);
// create mouseBox:
QGroupBox *mouseBox = new QGroupBox("Mouse:",generalTab);
QFormLayout *formLayoutMouse = new QFormLayout();
mouseBox->setLayout(formLayoutMouse);
repositionButton = new QPushButton("Reposition");
connect(repositionButton, SIGNAL(clicked()), this, SLOT(reposition()));
resetButton = new QPushButton("Reset");
connect(resetButton, SIGNAL(clicked()), this, SLOT(reset()));
smoothnessSlider = new QSlider(Qt::Horizontal);
smoothnessSlider->setMinimum(0);
smoothnessSlider->setMaximum(100);
smoothnessSlider->setTickInterval(10);
smoothnessSlider->setValue(50);
smoothnessSlider->setTickPosition(QSlider::TicksBelow);
speedSlider = new QSlider(Qt::Horizontal);
speedSlider->setMinimum(0);
speedSlider->setMaximum(100);
speedSlider->setTickInterval(10);
speedSlider->setValue(50);
speedSlider->setTickPosition(QSlider::TicksBelow);
formLayoutMouse->addRow("Smoothness:", smoothnessSlider);
formLayoutMouse->addRow("Speed:", speedSlider);
formLayoutMouse->addRow("Reposition Cursor:", repositionButton);
formLayoutMouse->addRow("Reset settings:", resetButton);
// add mousebox to main layout
generalTabLayout->addWidget(mouseBox);
// create saveFileBox:
QGroupBox *saveFileBox = new QGroupBox("Save: ", generalTab);
QFormLayout *saveFileLayout = new QFormLayout();
saveFileBox->setLayout(saveFileLayout);
saveFileName = new QLineEdit();
saveButton = new QPushButton("Save");
connect(saveButton,SIGNAL(clicked()),this,SLOT(save()));
saveFileLayout->addRow("Name file: ", saveFileName);
saveFileLayout->addRow("",saveButton);
// add saveFileBox to main layout
generalTabLayout->addWidget(saveFileBox);
/*
QVBoxLayout *mainSaveBoxLayout = new QVBoxLayout();
saveFileBox->setLayout(mainSaveBoxLayout);
QWidget *saveLabelBox = new QWidget();
QHBoxLayout *saveLabelLayout= new QHBoxLayout();
saveLabelBox->setLayout(saveLabelLayout);
QLabel *saveLabel= new QLabel("Save as: ");
QTextEdit *saveFileText = new QTextEdit();
*/
// add general page to tabPanel:
tabPanel->addTab(generalTab,"General");
}
void MainWindow::createCalibrationTab(QWidget *parent)
{
// create calibration page:
calibrationTab = new QWidget(parent);
QVBoxLayout *calibrationMainLayout = new QVBoxLayout();
calibrationTab->setLayout(calibrationMainLayout);
// create calibration pagecontent:
// create camera Box:
QGroupBox *cameraBox = new QGroupBox("Camera: ");
QFormLayout *cameraFormLayout = new QFormLayout();
cameraBox->setLayout(cameraFormLayout);
switchCameraButton = new QPushButton("Switch");
connect(switchCameraButton,SIGNAL(clicked()),this,SLOT(switchCamera()));
cameraFormLayout->addRow("Switch camera:", switchCameraButton);
// add foto option to camera:
fotoButton = new QPushButton("foto");
connect(fotoButton,SIGNAL(clicked()),this,SLOT(makeFoto()));
cameraFormLayout->addRow("Make foto: ", fotoButton);
//add camera box to calibrationmainLayout:
calibrationMainLayout->addWidget(cameraBox);
// create Mask Box:
QGroupBox *maskBox = new QGroupBox("Mask: ");
QFormLayout *maskFormLayout = new QFormLayout();
maskBox->setLayout(maskFormLayout);
maskLowerBound = new QLineEdit();
maskLowerBound->setText("0");
maskUpperBound = new QLineEdit();
maskUpperBound->setText("0");
maskFormLayout->addRow("Lower mask bound:", maskLowerBound);
maskFormLayout->addRow("Upper mask bound:", maskUpperBound);
// add mask box to calibrationMainLayout
calibrationMainLayout->addWidget(maskBox);
// add calibration page to tabPanel
tabPanel->addTab(calibrationTab,"Calibration");
}
// methods:
//*********************************************************************************************************************
void MainWindow::initiateTimer(){
paintTimer = new QTimer(this);
connect(paintTimer,SIGNAL(timeout()),dispatcher,SLOT(dispatchFrame()));
paintTimer->start(1000/DEFAULT_FPS);
}
void MainWindow::closeEvent(QCloseEvent *event){
quit();
}
void MainWindow::cleanUp(){
paintTimer->stop();
delete dispatcher;
}
// Slots:
//*********************************************************************************************************************
void MainWindow::save(){
QString filename;
filename = saveFileName->text();
if(filename == "")
{
QMessageBox *msgbox = new QMessageBox();
msgbox->setText("The file name is empty!\n Type in the full path with file name into General->Save menu.");
msgbox->exec();
}
else
{
saveFileThread *thread = new saveFileThread(1, filename.toStdString());
thread->start();
}
}
void MainWindow::load(){
}
void MainWindow::quit(){
/*QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Mouth", "Do you really want to quit?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes){
cleanUp();
qApp->quit();
}*/
cleanUp();
qApp->quit();
}
// butons:
void MainWindow::start(){
}
void MainWindow::stop(){
}
void MainWindow::reposition()
{
}
void MainWindow::reset()
{
}
void MainWindow::switchCamera()
{
Camera *camera = Camera::getInstance();
camera->switchCamera();
}
Mat *MainWindow::makeFoto(){
Camera *cam = Camera::getInstance();
Mat *image = cam->read();
return image;
}