-
Notifications
You must be signed in to change notification settings - Fork 0
/
facialemotion
32 lines (28 loc) · 1.02 KB
/
facialemotion
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
import cv2
from deepface import DeepFace
facecascade = cv2.CascadeClassifier(cv2.data.haarcascades + "C:/Users/Desktop/haarcascade_frontalface_default.xml")
cap = cv2.VideoCapture(1)
if not cap.isOpened():
cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise IOerror("cannot open webcam")
while True:
ret, frame = cap.read()
result= DeepFace.analyze('emotion' )
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray,1.1,4)
for(x, y, w, h) in faces:
cv2.rectangle(frame, (x,y),(x+w, y+h),(0,255,0),2)
font = cv2. FONT_HERSHEY_SIMPLEX
cv2.putText(frame,
result['dominant_emotion'],
(50, 50),
font, 3,
(0, 0, 255),
2,
cv2.LINE_4)
cv2.imshow('original video', frame)
if cv2.waitKey(2)& 0xFF== ord('q'):
break
cap.release()
cv2.destroyAllWindows()