forked from dguari1/Emotrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_window.py
460 lines (344 loc) · 17.4 KB
/
settings_window.py
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 26 16:10:14 2017
@author: GUARIND
"""
import os
import sys
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
import numpy as np
from dlib import shape_predictor
QtWidgets.QFrame
class QHLine(QtWidgets.QFrame):
def __init__(self):
super(QHLine, self).__init__()
self.setFrameShape(QtWidgets.QFrame.HLine)
self.setFrameShadow(QtWidgets.QFrame.Sunken)
class QVLine(QtWidgets.QFrame):
def __init__(self):
super(QHLine, self).__init__()
self.setFrameShape(QtWidgets.QFrame.VLine)
self.setFrameShadow(QtWidgets.QFrame.Sunken)
class LandMarksTab(QtWidgets.QWidget):
def __init__(self,parent=None, size_landmarks = None, shape = None):
super(LandMarksTab, self) .__init__(parent)
self._tab_name = 'Landmarks'
self._size_landmarks = size_landmarks
self._label1 = QtWidgets.QLabel('Landmark Diameter:')
self._Landmark_Size_Edit = QtWidgets.QLineEdit(self)
self._Landmark_Size_Edit.setFixedWidth(50)
validator = QtGui.QIntValidator(self)
validator.setBottom(1)
validator.setTop(99)
self._Landmark_Size_Edit.setValidator(validator)
self._label2 = QtWidgets.QLabel('px')
if size_landmarks is not None:
self._Landmark_Size_Edit.setText(str(size_landmarks))
else:
if shape is not None:
if shape[36,1]!=-1 and shape[39,1]!=-1:
size_landmarks = np.round(0.025*np.sqrt((shape[39,0]-shape[36,0])**2 + (shape[39,1]-shape[36,1])**2),0)
size_landmarks = int(np.floor(size_landmarks))
else:
size_landmarks = np.round(0.025*np.sqrt((shape[42,0]-shape[45,0])**2 + (shape[42,1]-shape[45,1])**2),0)
size_landmarks = int(np.floor(size_landmarks))
layout = QtWidgets.QGridLayout()
layout.addWidget(self._label1, 0,0,1,1)
layout.addWidget(self._Landmark_Size_Edit, 0,1,1,1)
layout.addWidget(self._label2, 0,2,1,1)
self.setLayout(layout)
class CalibrationTab(QtWidgets.QWidget):
def __init__(self,parent=None, CalibrationType = 'Iris', CalibrationValue = 11.77):
super(CalibrationTab, self) .__init__(parent)
#spacerh = QHLine()#QtWidgets.QWidget(self)
#spacerh.setFixedSize(10,0)
#spacerv = QtWidgets.QWidget(self)
#spacerv.setFixedSize(0,10)
self._tab_name = 'Calibration'
self._CalibrationType = CalibrationType
self._CalibratioValue = CalibrationValue
#checkbox
self._checkBox2 = QtWidgets.QCheckBox('Personalized Value', self)
self._checkBox1 = QtWidgets.QCheckBox('Iris Diameter', self)
#self._checkBox3 = QtWidgets.QCheckBox('Subject and Camera Distance', self)
self._CheckButtonGroup = QtWidgets.QButtonGroup(self)
self._CheckButtonGroup.addButton(self._checkBox1,1)
self._CheckButtonGroup.addButton(self._checkBox2,2)
#self._CheckButtonGroup.addButton(self._checkBox3,3)
self._Personalized_Edit = QtWidgets.QLineEdit(self)
self._Personalized_Edit.setFixedWidth(100)
#self._Personalized_Edit.setText("")
self._label2a = QtWidgets.QLabel('mm/px')
self._IrisDiameter_Edit = QtWidgets.QLineEdit(self)
self._IrisDiameter_Edit.setFixedWidth(100)
#self._IrisDiameter_Edit.setText("11.77")
self._label1a = QtWidgets.QLabel('mm')
if self._CalibrationType == 'Iris':
self._checkBox1.setChecked(True)
self._checkBox2.setChecked(False)
self._Personalized_Edit.setText("")
self._IrisDiameter_Edit.setText(str(self._CalibratioValue))
else:
self._checkBox1.setChecked(False)
self._checkBox2.setChecked(True)
self._Personalized_Edit.setText(str(self._CalibratioValue))
self._IrisDiameter_Edit.setText("")
layout = QtWidgets.QGridLayout()
layout.addWidget(self._checkBox1, 0,0,1,1)
layout.addWidget(self._IrisDiameter_Edit, 1,0,1,1)
layout.addWidget(self._label1a, 1,1,1,1)
layout.addWidget(QHLine(),2,0)
layout.addWidget(self._checkBox2, 3,0,1,1)
layout.addWidget(self._Personalized_Edit, 4,0,1,1)
layout.addWidget(self._label2a, 4,1,1,1)
self.setLayout(layout)
class ModelTab(QtWidgets.QWidget):
def __init__(self,parent=None, ModelName='iBUG'):
super(ModelTab, self) .__init__(parent)
if os.name is 'posix': #is a mac or linux
scriptDir = os.path.dirname(sys.argv[0])
else: #is a windows
scriptDir = os.getcwd()
#spacerh = QHLine()#QtWidgets.QWidget(self)
#spacerh.setFixedSize(10,0)
#spacerv = QtWidgets.QWidget(self)
#spacerv.setFixedSize(0,10)
self._ModelName=ModelName
self._tab_name = 'Model'
#checkbox
self._checkBox2 = QtWidgets.QCheckBox('iBUG Database', self)
self._checkBox1 = QtWidgets.QCheckBox('MEEI Database', self)
self._checkBox3 = QtWidgets.QCheckBox('', self) #this checkbox won't appear, it is only for tabs keeping
if self._ModelName == 'iBUG':
self._checkBox1.setChecked(False)
self._checkBox2.setChecked(True)
self._checkBox3.setChecked(False)
elif self._ModelName == 'MEE':
self._checkBox1.setChecked(True)
self._checkBox2.setChecked(False)
self._checkBox3.setChecked(False)
else:
self._checkBox1.setChecked(False)
self._checkBox2.setChecked(False)
self._checkBox3.setChecked(True)
#self._checkBox3 = QtWidgets.QCheckBox('Subject and Camera Distance', self)
self._CheckButtonGroup = QtWidgets.QButtonGroup(self)
self._CheckButtonGroup.addButton(self._checkBox1,1)
self._CheckButtonGroup.addButton(self._checkBox2,2)
self._CheckButtonGroup.addButton(self._checkBox3,3)
self._help_checkBox1 = QtWidgets.QPushButton('', self)
self._help_checkBox1.setIcon(QtGui.QIcon(scriptDir + os.path.sep + 'include' +os.path.sep +'icon_color'+ os.path.sep + 'question_icon.png'))
self._help_checkBox1.clicked.connect(lambda: self.push_help_checkBox1())
self._help_checkBox1.setIconSize(QtCore.QSize(20,20))
self._help_checkBox2 = QtWidgets.QPushButton('', self)
self._help_checkBox2.setIcon(QtGui.QIcon(scriptDir + os.path.sep + 'include' +os.path.sep +'icon_color'+ os.path.sep + 'question_icon.png'))
self._help_checkBox2.clicked.connect(lambda: self.push_help_checkBox2())
self._help_checkBox2.setIconSize(QtCore.QSize(20,20))
self._select_own_models = QtWidgets.QPushButton('Select Model', self)
self._select_own_models.clicked.connect(lambda: self.select_model())
self._select_own_models.setIconSize(QtCore.QSize(55,50))
layout = QtWidgets.QGridLayout()
layout.addWidget(self._checkBox1, 0,0)
layout.addWidget(self._help_checkBox1, 0,1)
layout.addWidget(QHLine(),1,0,1,2)
layout.addWidget(self._checkBox2, 2,0,1,1)
layout.addWidget(self._help_checkBox2, 2,1,1,1)
layout.addWidget(QHLine(),3,0,1,2)
layout.addWidget(self._checkBox3, 4,0,1,1)
layout.addWidget(self._select_own_models, 4,0,1,2)
self.setLayout(layout)
def select_model(self):
#load a file using the widget
name,_ = QtWidgets.QFileDialog.getOpenFileName(
self,'Load Model',
'',"dat files (*.dat)")
if not name:
pass
else:
self._ModelName = os.path.normpath(name)
#test if we can use the model
try: #try to load the model provided by the user
_ = shape_predictor(os.path.normpath(self._ModelName)) #just verify that te model can be loaded (...)
self._checkBox1.setChecked(False)
self._checkBox2.setChecked(False)
self._checkBox3.setChecked(True)
except: #if it doesn't work, load the MEE model
#show error message
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Information)
msg.setText("Provided model cannot be used. ")
msg.setInformativeText("Emotrics will use MEEI model instead.")
msg.setWindowTitle("Model Error")
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
msg.exec_()
self._checkBox1.setChecked(True)
self._checkBox2.setChecked(False)
self._checkBox3.setChecked(False)
print(name)
def push_help_checkBox1(self):
QtWidgets.QMessageBox.information(self, 'MEEI Database',
'Database created using front face, standard clinical photographs from facial palsy patients',
QtWidgets.QMessageBox.Ok)
def push_help_checkBox2(self):
QtWidgets.QMessageBox.information(self, 'iBUG Database',
'Database created as part of the iBUG project, it contains thousands of images taken in the wild along with face portaits obtained from the web',
QtWidgets.QMessageBox.Ok)
#class LandmarksSizeandColorTab(QtWidgets.QWidget):
#
# def __init__(self,parent=None, LandmarksSize=1, LandmarksColor=None):
# super(LandmarksSizeandColorTab, self) .__init__(parent)
#
# if os.name is 'posix': #is a mac or linux
# scriptDir = os.path.dirname(sys.argv[0])
# else: #is a windows
# scriptDir = os.getcwd()
#
# #spacerh = QHLine()#QtWidgets.QWidget(self)
# #spacerh.setFixedSize(10,0)
#
# #spacerv = QtWidgets.QWidget(self)
# #spacerv.setFixedSize(0,10)
#
# self._LandmarksSize = LandmarksSize
# self._LandmarksColor = LandmarksColor
#
# self._tab_name = 'Landmarks'
#
#
# #checkbox
# self._checkBox2 = QtWidgets.QCheckBox('iBUG Database', self)
# self._checkBox1 = QtWidgets.QCheckBox('MEEI Database', self)
# if self._ModelName == 'iBUG':
# self._checkBox1.setChecked(False)
# self._checkBox2.setChecked(True)
# else:
# self._checkBox1.setChecked(True)
# self._checkBox2.setChecked(False)
# #self._checkBox3 = QtWidgets.QCheckBox('Subject and Camera Distance', self)
#
#
# self._CheckButtonGroup = QtWidgets.QButtonGroup(self)
# self._CheckButtonGroup.addButton(self._checkBox1,1)
# self._CheckButtonGroup.addButton(self._checkBox2,2)
# #self._CheckButtonGroup.addButton(self._checkBox3,3)
#
# self._help_checkBox1 = QtWidgets.QPushButton('', self)
# self._help_checkBox1.setIcon(QtGui.QIcon(scriptDir + os.path.sep + 'include' +os.path.sep +'icon_color'+ os.path.sep + 'question_icon.png'))
# self._help_checkBox1.clicked.connect(lambda: self.push_help_checkBox1())
# self._help_checkBox1.setIconSize(QtCore.QSize(20,20))
#
#
# self._help_checkBox2 = QtWidgets.QPushButton('', self)
# self._help_checkBox2.setIcon(QtGui.QIcon(scriptDir + os.path.sep + 'include' +os.path.sep +'icon_color'+ os.path.sep + 'question_icon.png'))
# self._help_checkBox2.clicked.connect(lambda: self.push_help_checkBox2())
# self._help_checkBox2.setIconSize(QtCore.QSize(20,20))
#
#
#
# layout = QtWidgets.QGridLayout()
#
# layout.addWidget(self._checkBox1, 0,0)
# layout.addWidget(self._help_checkBox1, 0,1)
# layout.addWidget(QHLine(),1,0,1,2)
# layout.addWidget(self._checkBox2, 2,0,1,1)
# layout.addWidget(self._help_checkBox2, 2,1,1,1)
#
# self.setLayout(layout)
#
#
# def push_help_checkBox1(self):
# QtWidgets.QMessageBox.information(self, 'MEEI Database',
# 'Database created using front face, standard clinical photographs from facial palsy patients',
# QtWidgets.QMessageBox.Ok)
#
# def push_help_checkBox2(self):
# QtWidgets.QMessageBox.information(self, 'iBUG Database',
# 'Database created as part of the iBUG project, it contains thousands of images taken in the wild along with face portaits obtained from the web',
# QtWidgets.QMessageBox.Ok)
class ShowSettings(QtWidgets.QDialog):
def __init__(self,parent=None, ModelName='iBUG', CalibrationType='Iris', CalibrationValue=11.77, size_landmarks = None, shape = None):
super(ShowSettings, self).__init__(parent)
self.setWindowTitle('Settings')
if os.name is 'posix': #is a mac or linux
scriptDir = os.path.dirname(sys.argv[0])
else: #is a windows
scriptDir = os.getcwd()
self.setWindowIcon(QtGui.QIcon(scriptDir + os.path.sep + 'include' +os.path.sep +'icon_color'+ os.path.sep + 'settings_icon.ico'))
self.isCanceled = False
self._ModelName = ModelName
self._CalibrationType = CalibrationType
self._CalibrationValue = CalibrationValue
self._size_landmarks = size_landmarks
self._shape = shape
self.tab1 = CalibrationTab(self, self._CalibrationType, self._CalibrationValue)
self.tab2 = ModelTab(self, self._ModelName)
self.tab3 = LandMarksTab(self, self._size_landmarks, self._shape)
self.main_Widget = QtWidgets.QTabWidget(self)
self.tab1.setAutoFillBackground(True)
self.tab2.setAutoFillBackground(True)
self.tab3.setAutoFillBackground(True)
self.main_Widget.addTab(self.tab1,self.tab1._tab_name)
self.main_Widget.addTab(self.tab2,self.tab2._tab_name)
self.main_Widget.addTab(self.tab3,self.tab3._tab_name)
#if tab2 is not None:
# tab2.setAutoFillBackground(True)
# self.main_Widget.addTab(tab2,tab2._tab_name)
#if tab3 is not None:
# tab3.setAutoFillBackground(True)
# self.main_Widget.addTab(tab3,'Difference')
self.buttonDone = QtWidgets.QPushButton('Done',self)
self.buttonDone.clicked.connect(self.handleReturn)
self.buttonCancel = QtWidgets.QPushButton('Cancel', self)
self.buttonCancel.clicked.connect(self.pressCanceled)
layout=QtWidgets.QVBoxLayout()
layout.addWidget(self.main_Widget)
layout = QtWidgets.QGridLayout()
layout.addWidget(self.main_Widget,0,0,2,2)
layout.addWidget(self.buttonDone,2,0,1,1)
layout.addWidget(self.buttonCancel,2,1,1,1)
self.setLayout(layout)
#self.show()
def pressCanceled(self):
self.isCanceled = True
self.handleClose()
def handleClose(self):
self.close()
def handleReturn(self):
if self.tab1._checkBox1.isChecked() == True:
IrisDiameter = self.tab1._IrisDiameter_Edit.text()
if not IrisDiameter:
QtWidgets.QMessageBox.information(self, 'Error',
'The iris diameter must be larger than zero',
QtWidgets.QMessageBox.Ok)
else:
IrisDiameter = float(IrisDiameter)
if IrisDiameter <= 0:
QtWidgets.QMessageBox.information(self, 'Error',
'The iris diameter must be larger than zero',
QtWidgets.QMessageBox.Ok)
else:
self.close()
elif self.tab1._checkBox2.isChecked() == True:
PersonalizedValue = self.tab1._Personalized_Edit.text()
if not PersonalizedValue:
QtWidgets.QMessageBox.information(self, 'Error',
'The personalized calibration value must be larger than zero',
QtWidgets.QMessageBox.Ok)
else:
PersonalizedValue = float(PersonalizedValue)
if PersonalizedValue <= 0:
QtWidgets.QMessageBox.information(self, 'Error',
'The personalized calibration value must be larger than zero',
QtWidgets.QMessageBox.Ok)
else:
self.close()
if __name__ == '__main__':
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
GUI = ShowSettings()
#GUI.show()
app.exec_()