Spaces:
Runtime error
Runtime error
Commit
·
ddd31a2
1
Parent(s):
e4c9916
Update app.py
Browse files
app.py
CHANGED
@@ -59,35 +59,7 @@ def getTranscription(path):
|
|
59 |
return transcription[0]
|
60 |
|
61 |
def process_frame(frame):
|
62 |
-
|
63 |
-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
64 |
-
|
65 |
-
# Find all the faces in the frame using a pre-trained convolutional neural network.
|
66 |
-
face_locations = face_recognition.face_locations(gray)
|
67 |
-
#face_locations = face_recognition.face_locations(gray, number_of_times_to_upsample=0, model="cnn")
|
68 |
-
|
69 |
-
if len(face_locations) > 0:
|
70 |
-
# Show the original frame with face rectangles drawn around the faces
|
71 |
-
for top, right, bottom, left in face_locations:
|
72 |
-
# cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
|
73 |
-
face_image = gray[top:bottom, left:right]
|
74 |
-
color_image = frame[top:bottom, left:right]
|
75 |
-
|
76 |
-
# Resize the face image to the desired size
|
77 |
-
resized_face_image = cv2.resize(face_image, (128,128))
|
78 |
-
|
79 |
-
try:
|
80 |
-
emotion = DeepFace.analyze(color_image,actions=['emotion'],detector_backend = backends[2],enforce_detection = False)# 2,3, 4 works
|
81 |
-
emotion_count += 1
|
82 |
-
print(emotion)
|
83 |
-
except Exception as e:
|
84 |
-
emotion = 0
|
85 |
-
pass
|
86 |
-
|
87 |
-
# Predict the class of the resized face image using the model
|
88 |
-
result = model.predict(resized_face_image)
|
89 |
-
print(result[0])
|
90 |
-
return result[0], emotion
|
91 |
|
92 |
|
93 |
def video_processing(video_file, encoded_video):
|
@@ -134,26 +106,47 @@ def video_processing(video_file, encoded_video):
|
|
134 |
if not ret:
|
135 |
break
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
try:
|
159 |
# your processing code here
|
|
|
59 |
return transcription[0]
|
60 |
|
61 |
def process_frame(frame):
|
62 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
def video_processing(video_file, encoded_video):
|
|
|
106 |
if not ret:
|
107 |
break
|
108 |
|
109 |
+
# Convert the frame to RGB color (face_recognition uses RGB)
|
110 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
111 |
+
|
112 |
+
# Find all the faces in the frame using a pre-trained convolutional neural network.
|
113 |
+
face_locations = face_recognition.face_locations(gray)
|
114 |
+
#face_locations = face_recognition.face_locations(gray, number_of_times_to_upsample=0, model="cnn")
|
115 |
+
|
116 |
+
if len(face_locations) > 0:
|
117 |
+
# Show the original frame with face rectangles drawn around the faces
|
118 |
+
for top, right, bottom, left in face_locations:
|
119 |
+
# cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
|
120 |
+
face_image = gray[top:bottom, left:right]
|
121 |
+
color_image = frame[top:bottom, left:right]
|
122 |
|
123 |
+
# Resize the face image to the desired size
|
124 |
+
resized_face_image = cv2.resize(face_image, (128,128))
|
125 |
+
|
126 |
+
try:
|
127 |
+
emotion = DeepFace.analyze(color_image,actions=['emotion'],detector_backend = backends[2],enforce_detection = False)# 2,3, 4 works
|
128 |
+
emotion_count += 1
|
129 |
+
print(emotion)
|
130 |
+
except Exception as e:
|
131 |
+
emotion = 0
|
132 |
+
pass
|
133 |
+
|
134 |
+
# Predict the class of the resized face image using the model
|
135 |
+
result = model.predict(resized_face_image)
|
136 |
+
print(result[0])
|
137 |
+
if result[0] == 'on_camera':
|
138 |
+
on_camera += 1
|
139 |
+
elif result[0] == 'off_camera':
|
140 |
+
off_camera += 1
|
141 |
+
total += 1
|
142 |
+
|
143 |
+
angry += emotion[0]['emotion']['angry']
|
144 |
+
disgust += emotion[0]['emotion']['disgust']
|
145 |
+
fear += emotion[0]['emotion']['fear']
|
146 |
+
happy += emotion[0]['emotion']['happy']
|
147 |
+
sad += emotion[0]['emotion']['sad']
|
148 |
+
surprise += emotion[0]['emotion']['surprise']
|
149 |
+
neutral += emotion[0]['emotion']['neutral']
|
150 |
|
151 |
try:
|
152 |
# your processing code here
|