-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Code for TRAKREX Program (without terminal).txt
More file actions
57 lines (45 loc) · 1.79 KB
/
Copy pathPython Code for TRAKREX Program (without terminal).txt
File metadata and controls
57 lines (45 loc) · 1.79 KB
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
import cv2
from deepface import DeepFace
import webbrowser
#faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(1)
# Check if the webcam is opened correctly
if not cap.isOpened():
cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cap.read() # read one image from a video
result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# print (faceCascade.empty())
faces = faceCascade.detectMultiScale(gray, 1.1, 4)
# DetectMultiscale detects the objects
# Draw a rectangle around the faces
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
# Use putText() method for
# inserting text on video
cv2.putText(frame,
result['dominant_emotion'],
(50, 50),
font, 3,
(0, 0, 255),
2,
cv2.LINE_4)
cv2.imshow('Trakrex', frame)
dominant_emotion = result['dominant_emotion']
if cv2.waitKey(2) & 0xFF == ord('q'):
if dominant_emotion == 'neutral':
webbrowser.open("https://trakrexx.wixsite.com/neutrality")
if dominant_emotion == 'happy':
webbrowser.open("https://trakrexx.wixsite.com/happiness")
if dominant_emotion == 'sad':
webbrowser.open("https://trakrexx.wixsite.com/sadness")
if dominant_emotion == 'angry':
webbrowser.open("https://trakrexx.wixsite.com/anger")
break
cap.release()
cv2.destroyAllWindows()