-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
76 lines (61 loc) · 1.78 KB
/
main.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
import cv2
import pygame
import time
import random
from deep import build_net
from cam import Camera
from time import sleep
if __name__ == '__main__':
model_emo = build_net()
video_camera = Camera(model_emo)
while True:
emotion_number = 0
exit_num = 0
prev_emo = ""
while True:
frame = video_camera.get_face()
cv2.imshow("image", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
exit_num = 1
break;
curr_emo = video_camera.get_emotion()
if (prev_emo == ""):
prev_emo = curr_emo
curr_emo = ""
else:
if (prev_emo == curr_emo):
emotion_number = emotion_number + 1
curr_emo = ""
else:
emotion_number = 0
prev_emo = curr_emo
curr_emo = ""
if (emotion_number == 5):
break;
sleep(0.1)
if exit_num == 1:
break;
rand = random.randint(1, 3)
if rand == 1:
file = "a.mp3"
elif rand == 2:
file = "b.mp3"
elif rand == 3:
file = "c.mp3"
music_path = "music/" + prev_emo + "/" + file
pygame.init()
pygame.display.set_mode((200, 100))
pygame.mixer.music.load(music_path)
pygame.mixer.music.play()
time.sleep(10)
cv2.destoryAllWindows()
"""
while True:
frame = video_camera.get_face()
cv2.imshow("image", frame)
print("11111111"+video_camera.get_emotion())
if cv2.waitKey(1) & 0xFF == ord('q'):
break
sleep(0.01)
cv2.destoryAllWindows()
"""