forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
73 lines (56 loc) · 1.98 KB
/
app.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
import cv2
import numpy as np
from fer import FER
scr = cv2.VideoCapture(0) #30fps
scr.set(3, 640)
scr.set(4, 480)
#init FRE (Facial expression recognition from images)
detector = FER(mtcnn=True)
while True:
ret,frame = scr.read()
# frame = cv2.flip(frame,1)
#return emotion name and % of true detection
emotion, score = detector.top_emotion(frame)
print(emotion,score)
if emotion == 'angry':
emoj = cv2.imread('https://i.ibb.co/QN0gqNH/angry.png')
elif emotion == 'disgust':
emoj = cv2.imread('https://i.ibb.co/tJDxrhD/disgust.png')
elif emotion == 'fear':
emoj = cv2.imread('https://i.ibb.co/yBczSFB/fear.png')
elif emotion == 'happy':
emoj = cv2.imread('https://i.ibb.co/g6DW0Cf/happy.png')
elif emotion == 'sad':
emoj = cv2.imread('https://i.ibb.co/NyF0sDq/sad.png')
elif emotion == 'surprise':
emoj = cv2.imread('https://i.ibb.co/D4rDyfM/surprise.png')
elif emotion == 'neutral':
emoj = cv2.imread('https://i.ibb.co/KX7VSjh/neutral.png')
else:
emoj = cv2.imread('https://i.ibb.co/LdnS9nL/none.png')
#Adding Image on Screen
# Read emoj and resize
size = 150
emoj = cv2.resize(emoj, (size, size))
# Create a mask of emoj
img2gray = cv2.cvtColor(emoj, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray, 1, 255, cv2.THRESH_BINARY)
roi = frame[-size-20:-20, -size-20:-20]
# roi = frame[-size-310:-310, -size-470:-470]
# Set an index of where the mask is
roi[np.where(mask)] = 0
roi += emoj
#add text
font = cv2.FONT_HERSHEY_SIMPLEX
org = (40, 210)
fontScale = 1
color = (255, 0, 0)
thickness = 2
cv2.putText(frame,emotion, org, font, fontScale, color, thickness, cv2.LINE_AA)
#show screen
cv2.imshow('frame',frame)
#stop
if cv2.waitKey(1) & 0xff == ord('q'):
break
scr.release()
cv2.destroyAllWindows()