-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
286 lines (211 loc) · 7.66 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
281
282
283
284
285
286
#include <qtimer.h>
#include <qvalidator.h>
#include <chrono>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "conversionutility.h"
#include "guigesturerecognitionhmm.h"
#include "guigesturerecognitiondtw.h"
#include "guigesturerecognitiontest.h"
#include "guigesturerecognitionsave.h"
#include "guitestmyo.h"
using namespace std;
using namespace std::chrono;
using namespace cv;
int totFrame;
double totTime;
MainWindow::MainWindow(QStringList arguments, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//-----------------------------------------------GUI-----------------------------------
ui->setupUi(this);
setFixedSize(this->geometry().width(), this->geometry().height());
// collegamento actions e altro
//connect(ui->actionBatchProcess1,SIGNAL(triggered()),this, SLOT(BatchProcess1()));
connect(ui->actionRun,SIGNAL(triggered(bool)),this, SLOT(Run(bool)));
connect(ui->actionClose,SIGNAL(triggered(bool)),this, SLOT(close()));
connect(ui->buttonStart, SIGNAL(released()), this, SLOT(doAll()));
connect(ui->buttonStart, SIGNAL(released()), this, SLOT(resetGUI()));
//--------------------------------------------FPS---------------------------------
totFrame = 0;
totTime = 0;
//--------------------------------------------Timer-------------------------------
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(processStep()));
_pkinect = nullptr;
}
void::MainWindow::doAll(){
// uccido eventuali kinect precedenti
if (_pkinect)
delete _pkinect;
_pkinect = nullptr;
//----------------------------DEVICES-----------------------------------
// Kinect 1
if(ui->radioKinect1->isChecked()){
_pkinect = new AcquisitionKinect1();
}
// Kinect 2
if(ui->radioKinect2->isChecked()){
_pkinect = new AcquisitionKinect2();
_pkinect->setSkeleton(MODE_CLOSEST);
_pkinect->setResolution(RESOLUTION_VGA);
}
// Myo
if(ui->radioMyo->isChecked()){
_pmyo = new AcquisitionMyo();
}
// File
if(ui->radioFile->isChecked())
_pkinect = new AcquisitionFile();
//-----------------------------------METHODS--------------------------------------
// HMM
if(ui->radioHMM->isChecked()){
_precognizer = new GestureRecognitionHMM();
GUIgesturerecognitionhmm *pGUI = new GUIgesturerecognitionhmm (dynamic_cast<GestureRecognitionHMM*>(_precognizer));
pGUI->setParent(ui->widgetL);
pGUI->show();
}
// DTW
if(ui->radioDTW->isChecked()){
_precognizer = new GestureRecognitionDTW();
GUIgesturerecognitiondtw *pGUI = new GUIgesturerecognitiondtw (dynamic_cast<GestureRecognitionDTW*>(_precognizer));
pGUI->setParent(ui->widgetL);
pGUI->show();
}
//---------------------------------UTILITY-------------------------------------
// Test
if(ui->radioTest->isChecked()){
_precognizer = new GestureRecognitionTEST();
GUIgesturerecognitiontest *pGUI = new GUIgesturerecognitiontest (dynamic_cast<GestureRecognitionTEST*>(_precognizer));
pGUI->setParent(ui->widgetL);
pGUI->show();
}
// Save Annotation
if(ui->radioSave->isChecked()){
_pmyo = new AcquisitionMyo();
_precognizer = new GestureRecognitionSave();
GUIgesturerecognitionsave *pGUI = new GUIgesturerecognitionsave (dynamic_cast<GestureRecognitionSave*>(_precognizer));
pGUI->setParent(ui->widgetL);
pGUI->show();
}
// Test MYO
if(ui->radioTestMyo->isChecked()){
_precognizer = new TestMyo();
GUItestMyo *pGUI = new GUItestMyo (dynamic_cast<TestMyo*>(_precognizer));
pGUI->setParent(ui->widgetL);
pGUI->show();
}
ui->widgetL->setVisible(true);
// Timer
timer->start(30);
}
void::MainWindow::resetGUI(){
ui->groupSource->hide();
ui->groupMethod->hide();
ui->buttonStart->hide();
}
void MainWindow::close(){
ui->widgetL->setVisible(false);
qDeleteAll(ui->widgetL->children());
ui->groupSource->setVisible(true);
ui->groupMethod->setVisible(true);
ui->buttonStart->setVisible(true);
ui->radioKinect1->setAutoExclusive(false);
ui->radioKinect1->setChecked(false);
ui->radioKinect1->setAutoExclusive(true);
ui->radioKinect2->setAutoExclusive(false);
ui->radioKinect2->setChecked(false);
ui->radioKinect2->setAutoExclusive(true);
ui->radioFile->setAutoExclusive(false);
ui->radioFile->setChecked(false);
ui->radioFile->setAutoExclusive(true);
ui->radioHMM->setAutoExclusive(false);
ui->radioHMM->setChecked(false);
ui->radioHMM->setAutoExclusive(true);
ui->radioDTW->setAutoExclusive(false);
ui->radioDTW->setChecked(false);
ui->radioDTW->setAutoExclusive(true);
ui->radioTest->setAutoExclusive(false);
ui->radioTest->setChecked(false);
ui->radioTest->setAutoExclusive(true);
ui->radioSave->setAutoExclusive(false);
ui->radioSave->setChecked(false);
ui->radioSave->setAutoExclusive(true);
Mat frameBlack;
frameBlack = Mat(200, 840, CV_8UC3, Scalar(0, 0, 0));
QPixmap pixBlack = cvMatToQPixmap(frameBlack);
ui->labelRGB->setPixmap(pixBlack.scaled(ui->labelRGB->size(), Qt::IgnoreAspectRatio));
Mat depthBlack;
depthBlack = Mat(200, 840, CV_8UC3, Scalar(0, 0, 0));
QPixmap depthpix= cvMatToQPixmap(depthBlack);
ui->labelDepth->setPixmap(depthpix.scaled(ui->labelDepth->size(), Qt::IgnoreAspectRatio));
ui->labelTimeAcq->setText("");
ui->labelTimeElab->setText("");
ui->labelTotal->setText("");
ui->labelFPS->setText("");
timer->stop();
}
void MainWindow::Run(bool brun){
if (timer!= nullptr){
if (brun)
timer->start(30);
else
timer->stop();
}
}
void MainWindow::processStep(){
high_resolution_clock timer;
using ms = duration<float, std::milli>;
//Get next frame KINECT
auto start = timer.now();
if(_pkinect != nullptr)
_pkinect->getFrame(frame);
auto stop = timer.now();
//GEt next frame MYO
if(_pmyo != nullptr){
_pmyo->getFrame(frame);
}
//if(frame.RGB.cols > 0)
totFrame++;
auto deltaTime = duration_cast<ms>(stop - start).count();
//totTime += deltaTime;
//Try to classify
start = timer.now();
if(_precognizer != nullptr)
_precognizer->recognize(frame);
stop = timer.now();
auto deltaTimeRec = duration_cast<ms>(stop - start).count();
totTime = totTime + deltaTime + deltaTimeRec;
if((deltaTime + deltaTimeRec) > 30){
totTime += 30;
}
double fps = (totFrame/totTime)*1000;
//cout << (totFrame/totTime)*1000 << endl;
//cout << totFrame << endl;
//Update main GUI (RGB + DEPTH)
Mat& frameRGB = frame.RGB;
Mat& frameDepth = frame.depth;
QPixmap pixFrameRGB = cvMatToQPixmap(frameRGB);
QPixmap pixFrameDepth = cvMatToQPixmap(frameDepth);
if(pixFrameRGB.isNull())
ui->labelRGB->setText("Image Null");
else
ui->labelRGB->setPixmap(pixFrameRGB.scaled(ui->labelRGB->size(), Qt::IgnoreAspectRatio));
if(pixFrameDepth.isNull())
ui->labelDepth->setText("Image Null");
else
ui->labelDepth->setPixmap(pixFrameDepth.scaled(ui->labelDepth->size(), Qt::IgnoreAspectRatio));
if(totFrame%2 == 0){
ui->labelTimeAcq->setText(QString::number(deltaTime));
ui->labelTimeElab->setText(QString::number(deltaTimeRec));
ui->labelTotal->setText(QString::number(deltaTime+deltaTimeRec));
ui->labelFPS->setText(QString::number((int)fps));
}
}
MainWindow::~MainWindow()
{
// uccido _pkinect
delete _pkinect;_pkinect=nullptr;
delete ui;
}