-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainWindow.cpp
281 lines (230 loc) · 7.09 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
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
#include <QtGui>
#include <QtWidgets>
#include "platform.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
//init a window to apply layout
QWidget* window = new QWidget(this);
//init a detecter
detecter = new Detection(this);
//init colorMode
colorMode = 1;
//init four window to show result
view1 = new showWindow(window);
view2 = new showWindow(window);
view3 = new showWindow(window);
view4 = new showWindow(window);
//init buttons
//openAction = new QAction(QIcon(":/images/file-open"), tr("&Open..."), this);
//openAction->setShortcuts(QKeySequence::Open);
//openAction->setStatusTip(tr("Open an existing file"));
//connect(openAction, &QAction::triggered, this, &MainWindow::openFile);
/*saveAction = new QAction(QIcon(":/images/file-save"), tr("&Save..."), this);
saveAction->setShortcuts(QKeySequence::Save);
saveAction->setStatusTip(tr("Save a new file"));
connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile);*/
startCameraAction = new QAction(tr("&Startcamera..."),this);
startCameraAction->setStatusTip(tr("Startfromcamera"));
connect(startCameraAction, &QAction::triggered, this, &MainWindow::openCamera);
detectFaceAction = new QAction(tr("&Detectface..."),this);
detectFaceAction->setStatusTip(tr("Start to detect face"));
connect(detectFaceAction, &QAction::triggered, this, &MainWindow::beginFaceDetect);
screenShotAction = new QAction(tr("&Screenshot..."), this);
screenShotAction->setStatusTip(tr("Take a screenshot and save the picture"));
connect(screenShotAction, &QAction::triggered, this, &MainWindow::beginScreenShot);
//stopAction = new QAction(tr("&Stop..."),this);
//stopAction -> setStatusTip(tr("Stop the video"));
//connect(stopAction, &QAction::triggered, view1, &Window::stopVideo);
////init menue
// QMenu *file = menuBar()->addMenu(tr("&File"));
// file->addAction(openAction);
// file->addAction(saveAction);
//file->addAction(screenShotAction);
//file->addAction(stopAction);
//init toolbar
QToolBar *toolBar = addToolBar(tr("&File"));
//toolBar->addAction(openAction);
//toolBar->addAction(saveAction);
toolBar->addAction(startCameraAction);
toolBar->addAction(detectFaceAction);
toolBar->addAction(screenShotAction);
//init labels
attr1 = new QLabel(tr("attr"));
attr2 = new QLabel(tr("attr"));
attr3 = new QLabel(tr("attr"));
attr4 = new QLabel(tr("attr"));
//init input boxes
QDoubleSpinBox* input1 = new QDoubleSpinBox();
input1->setMaximumWidth(50);
QSpinBox* input2 = new QSpinBox();
input2->setMaximumWidth(50);
QSpinBox* input3 = new QSpinBox();
input3->setMaximumWidth(50);
QSpinBox* input4 = new QSpinBox();
input4->setMaximumWidth(50);
//left form layout
QFormLayout* form = new QFormLayout();
form->addRow("ScaleFactor",input1);
form->addRow("MinNeighbors",input2);
form->addRow("MinX",input3);
form->addRow("MinY",input4);
form->addRow(attr1);
form->addRow(attr2);
form->addRow(attr3);
form->addRow(attr4);
//init a widget to hold the form
QWidget* widgetForm = new QWidget();
widgetForm->setLayout(form);
widgetForm->setMaximumWidth(120);
//the main grid layout
QGridLayout *mainLayout = new QGridLayout();
mainLayout ->addWidget(widgetForm,0,0,2,1);
mainLayout ->addWidget(view1,0,1,1,1);
mainLayout ->addWidget(view2,0,2,1,1);
mainLayout ->addWidget(view3,1,1,1,1);
mainLayout ->addWidget(view4,1,2,1,1);
//apply the layout
this->setCentralWidget(window);
this->centralWidget()->setLayout(mainLayout);
//init timer
timer=new QTimer(this);
//connect for signals and slots
connect(detecter,&Detection::sendScreenShot,this,&MainWindow::beginScreenShot);
connect(input1,SIGNAL(valueChanged(double)),this,SLOT(setScaleFactor(double)));
connect(input2,SIGNAL(valueChanged(int)),this,SLOT(setMinNeighbors(int)));
connect(input3,SIGNAL(valueChanged(int)),this,SLOT(setMinX(int)));
connect(input4,SIGNAL(valueChanged(int)),this,SLOT(setMinY(int)));
connect(detecter,&Detection::toSetLabel,this,&MainWindow::setLabel);
connect(timer,&QTimer::timeout,this,&MainWindow::eachFrame);
//set bool
ifDetectFace =true;
ifDetectRGBHist = ifShot = false;
}
MainWindow::~MainWindow()
{
delete timer;
delete openAction;
delete saveAction;
delete screenShotAction;
delete stopAction;
delete startCameraAction;
delete detectFaceAction;
delete detecter;
delete view1;
delete view2;
delete view3;
delete view4;
delete attr1;
delete attr2;
delete attr3;
delete attr4;
}
//void MainWindow::openFile()
//{
// QString path = QFileDialog::getOpenFileName(this, tr("Open File"), ".", tr("avi file(*.avi)"));
// if(!path.isEmpty()) {
// /*QFile file(path);
// if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// QMessageBox::warning(this, tr("Read File"), tr("Cannot open file:\n%1").arg(path));
// return;*/
// capture = cv::VideoCapture(path.toStdString());
// if(capture.isOpened())
// playVedio(capture);
// else
// QMessageBox::warning(this, tr("Open vedio failed"), tr("fail to open the vedio."));
//
// //view1->showImage(img);
// }
// else {
// QMessageBox::warning(this, tr("Path"), tr("You did not select any file."));
// }
//}
void MainWindow::openCamera()
{
capture = cv::VideoCapture(0);
timer->start(1000/60);
}
void MainWindow::eachFrame()
{
capture>>frame;
//frame.copyTo(frame2);
//frame2 = frame.clone();
colorMode = 1;
if(ifDetectFace)
{
detecter->detectFace(frame,S,N,X,Y);
view1->showImage(frame, colorMode);
}
else
{
view1->showImage(frame, colorMode);
}
if(ifDetectRGBHist)
{
}
if(ifShot)
{
cv::Mat shot = cv::Mat(frame);
view2->showImage(frame, colorMode);
if(colorMode==-1)
{
cv::cvtColor(frame,frame,CV_RGB2BGR);
colorMode = 1;
}
QDateTime time = QDateTime::currentDateTime();
QString filename = time.toString("yyyy-MM-dd hh-mm-ss");
cv::imwrite("screenshot"+filename.toStdString()+".png",frame);
ifShot = false;
}
}
//void MainWindow::saveFile()
//{
// QString path = QFileDialog::getSaveFileName(this, tr("Save File"), ".", tr("Text Files(*.txt)"));
// if(!path.isEmpty()) {
// QFile file(path);
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
// QMessageBox::warning(this, tr("Write File"), tr("Cannot open file:\n%1").arg(path));
// return;
// }
// QTextStream out(&file);
// out << textEdit->toPlainText();
// file.close();
// } else {
// QMessageBox::warning(this, tr("Path"), tr("You did not select any file."));
// }
//}
void MainWindow::setLabel(int i , QString str)
{
switch(i)
{
case 1: attr1->setText(str);attr1->show();break;
case 2: attr2->setText(str);attr2->show();break;
case 3: attr3->setText(str);attr3->show();break;
case 4: attr4->setText(str);attr4->show();break;
}
}
void MainWindow::beginFaceDetect()
{
ifDetectFace = !ifDetectFace;
}
void MainWindow::beginScreenShot()
{
ifShot = true;
}
void MainWindow::setScaleFactor(double S)
{
S = S;
}
void MainWindow::setMinNeighbors(int N)
{
N = N;
}
void MainWindow::setMinX(int X)
{
X = X;
}
void MainWindow::setMinY(int Y)
{
Y = Y;
}