forked from hirohe/facerec-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.py
163 lines (133 loc) · 5.92 KB
/
mainwindow.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
# -*- coding: utf-8 -*-
import datetime
from time import strftime
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
style = QString(open('./ui/css/style.css').read())
class Ui_MainWindow(QMainWindow):
model = None
def __init__(self):
super(Ui_MainWindow, self).__init__()
self.setupUi(self)
self.setStyleSheet(style)
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(480, 800)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.label_date = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(28)
self.label_date.setFont(font)
self.verticalLayout.addWidget(self.label_date)
self.lcd_time = QtGui.QLCDNumber(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(24)
self.lcd_time.setFont(font)
self.lcd_time.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.lcd_time.setDigitCount(8)
self.lcd_time.setLayoutDirection(QtCore.Qt.LeftToRight)
self.verticalLayout.addWidget(self.lcd_time)
self.label_welcome = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(28)
self.label_welcome.setFont(font)
self.label_welcome.setAlignment(QtCore.Qt.AlignCenter)
self.verticalLayout.addWidget(self.label_welcome)
self.gridLayout_buttons = QtGui.QGridLayout()
self.gridLayout_buttons.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
self.gridLayout_buttons.setMargin(0)
self.gridLayout_buttons.setSpacing(50)
#button face
self.btn_face = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_face.sizePolicy().hasHeightForWidth())
self.btn_face.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(26)
self.btn_face.setFont(font)
self.gridLayout_buttons.addWidget(self.btn_face, 0, 0, 1, 1)
self.btn_face.clicked.connect(self.btn_face_clicked)
#button register
self.btn_register = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_register.sizePolicy().hasHeightForWidth())
self.btn_register.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(26)
self.btn_register.setFont(font)
self.gridLayout_buttons.addWidget(self.btn_register, 1, 0, 1, 1)
self.btn_register.clicked.connect(self.btn_register_clicked)
self.verticalLayout.addLayout(self.gridLayout_buttons)
self.verticalLayout.setStretch(0, 1)
self.verticalLayout.setStretch(1, 2)
self.verticalLayout.setStretch(2, 1)
self.verticalLayout.setStretch(3, 4)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 480, 23))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self._timer = QtCore.QTimer(self)
self._timer.timeout.connect(self.updateTime)
self._timer.start(1000)
self.update()
def updateTime(self):
# date = datetime.datetime.now().strftime(' %Y-%m-%d')
dateNow = datetime.datetime.now()
dy = dateNow.strftime(' %Y')
dm = dateNow.strftime('%m')
dd = dateNow.strftime('%d')
time = dateNow.strftime('%H:%M:%S')
self.label_date.setText(dy+u'年'+dm+u'月'+dd+u'日')
# self.lcd_time.setText(time)
self.lcd_time.display(strftime("%H"+":"+"%M"+":"+"%S"))
def setModel(self, model):
self.model = model
def setVideo(self, video):
self.video = video
def btn_face_clicked(self):
print 'facerec clicked'
self.video.open(0)
self._timer.stop()
self.facerec = ui.FaceRec(self)
self.facerec.setModel(self.model)
self.facerec.setVideo(self.video)
self.setCentralWidget(self.facerec)
def btn_register_clicked(self):
print 'face register'
self._timer.stop()
self.register = ui.FaceRegister(self)
self.register.setModel(self.model)
self.register.setVideo(self.video)
self.setCentralWidget(self.register)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label_date.setText(_translate("MainWindow", u" 0000年00月00日", None))
self.label_welcome.setText(unicode(u"人脸识别系统"))
self.btn_face.setText(u"人脸识别")
self.btn_register.setText(u"人脸录入")