abrar-adnan commited on
Commit
ddd31a2
·
1 Parent(s): e4c9916

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -48
app.py CHANGED
@@ -59,35 +59,7 @@ def getTranscription(path):
59
  return transcription[0]
60
 
61
  def process_frame(frame):
62
- # Convert the frame to RGB color (face_recognition uses RGB)
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
- result, emotion = process_frame(frame)
139
- print(emotion)
140
- if result:
141
- if result == 'on_camera':
142
- on_camera += 1
143
- elif result == 'off_camera':
144
- off_camera += 1
145
- total += 1
146
-
147
- if emotion != 0:
148
- # print(emotion[0]['emotion'])
149
-
150
- angry += emotion[0]['emotion']['angry']
151
- disgust += emotion[0]['emotion']['disgust']
152
- fear += emotion[0]['emotion']['fear']
153
- happy += emotion[0]['emotion']['happy']
154
- sad += emotion[0]['emotion']['sad']
155
- surprise += emotion[0]['emotion']['surprise']
156
- neutral += emotion[0]['emotion']['neutral']
 
 
 
 
 
 
 
 
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