-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_fon1.py
140 lines (117 loc) · 4.26 KB
/
form_fon1.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
from PyQt5.QtWidgets import (QWidget, QToolTip, QPushButton, QApplication, QLabel, QVBoxLayout)
from PyQt5.QtCore import QTimer, Qt
from PyQt5.QtGui import QIcon, QImage, QPixmap
import cv2
import find_face_video as f
import emotion_video as e
import dots
class QtCapture(QWidget):
global a
a = 0
def __init__(self, *args):
super(QWidget, self).__init__()
self.cap = cv2.VideoCapture(*args)
self.video_frame = QLabel()
lay = QVBoxLayout()
lay.addWidget(self.video_frame)
self.setLayout(lay)
def nextFrameSlot(self):
ret, frame = self.cap.read()
if a == 1:
frame = f.find_face(frame)
elif a == 2:
image = e.format_image(frame)
frame = e.emotions(image, frame)
elif a == 3:
image = e.format_image(frame)
frame = e.emotions(image, frame)
frame = f.find_face(frame)
elif a == 4:
dots.angry(frame)
dots.happydots(frame)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
pix = QPixmap.fromImage(img)
self.video_frame.setPixmap(pix)
def start(self):
global a
a = 0
self.timer = QTimer()
self.timer.timeout.connect(self.nextFrameSlot)
self.timer.start(1000./30) # задаем fps
def stop(self):
self.timer.stop()
def deleteLater(self):
self.cap.release()
super(QWidget, self).deleteLater()
def key_points(self):
global a
a = 1
self.timer = QTimer()
self.timer.timeout.connect(self.nextFrameSlot)
self.timer.start(1000./30) # задаем fps
def emotion(self):
global a
a = 2
self.timer = QTimer()
self.timer.timeout.connect(self.nextFrameSlot)
self.timer.start(1000./30) # задаем fps
def new_emotion(self):
global a
a = 3
self.timer = QTimer()
self.timer.timeout.connect(self.nextFrameSlot)
self.timer.start(1000. / 30) # задаем fps
def dots_emotion(self):
global a
a = 4
self.timer = QTimer()
self.timer.timeout.connect(self.nextFrameSlot)
self.timer.start(1000. / 60) # задаем fps
class ControlWindow(QWidget):
def __init__(self):
QWidget.__init__(self)
self.capture = None
self.start_button = QPushButton('зеркало')
self.start_button.clicked.connect(self.startCapture)
self.quit_button = QPushButton('выход')
self.quit_button.clicked.connect(self.endCapture)
self.new_emotion = QPushButton('Тренировка')
self.key_points_button = QPushButton('точки')
self.emotion_button = QPushButton('эмоции')
self.angry_button = QPushButton('angry')
self.end_button = QPushButton('пауза')
vbox = QVBoxLayout(self)
vbox.addWidget(self.start_button)
vbox.addWidget(self.new_emotion)
vbox.addWidget(self.end_button)
vbox.addWidget(self.key_points_button)
vbox.addWidget(self.emotion_button)
vbox.addWidget(self.angry_button)
vbox.addWidget(self.quit_button)
self.setLayout(vbox)
self.setWindowTitle('управление')
self.setGeometry(100, 100, 220, 200)
self.show()
def startCapture(self):
if not self.capture:
self.capture = QtCapture(0)
self.end_button.clicked.connect(self.capture.stop)
self.angry_button.clicked.connect(self.capture.dots_emotion)
self.key_points_button.clicked.connect(self.capture.key_points)
self.emotion_button.clicked.connect(self.capture.emotion)
self.new_emotion.clicked.connect(self.capture.new_emotion)
# self.capture.setFPS(1)
self.capture.setParent(self)
self.capture.setWindowFlags(Qt.Tool)
self.capture.start()
self.capture.show()
def endCapture(self):
self.capture.deleteLater()
self.capture = None
QApplication.quit()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = ControlWindow()
sys.exit(app.exec_())