felix.wf commited on
Commit
be331fc
·
1 Parent(s): 1448eef

add feature in video process

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -134,7 +134,7 @@ if file_name is not None:
134
  frame_interval = frame_rate # Process one frame per second
135
 
136
  frame_emotions = []
137
-
138
  for frame_idx in range(0, frame_count, frame_interval):
139
  video.set(cv2.CAP_PROP_POS_FRAMES, frame_idx)
140
  ret, frame = video.read()
@@ -160,8 +160,14 @@ if file_name is not None:
160
  output = pipe_emotions(face)
161
  frame_emotion.append(output[0]['label'])
162
  frame_emotions.append(frame_emotion)
 
 
 
 
 
 
163
 
164
- # Plot emotions over frames
165
  fig, ax = plt.subplots(figsize=(10, 5))
166
  ax.plot(range(len(frame_emotions)), [len(emotions) for emotions in frame_emotions], label='Number of Persons Detected')
167
  ax.set_xlabel('Frame')
@@ -171,5 +177,17 @@ if file_name is not None:
171
 
172
  st.pyplot(fig)
173
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  else:
175
  st.error("Unsupported file type. Please upload an image or a video.")
 
134
  frame_interval = frame_rate # Process one frame per second
135
 
136
  frame_emotions = []
137
+ frame_emotions_refined = []
138
  for frame_idx in range(0, frame_count, frame_interval):
139
  video.set(cv2.CAP_PROP_POS_FRAMES, frame_idx)
140
  ret, frame = video.read()
 
160
  output = pipe_emotions(face)
161
  frame_emotion.append(output[0]['label'])
162
  frame_emotions.append(frame_emotion)
163
+
164
+ frame_emotion_refined = []
165
+ for face in persons_image_list:
166
+ output = pipe_emotions_refined(face)
167
+ frame_emotion_refined.append(output[0]['label'])
168
+ frame_emotions_refined.append(frame_emotion_refined)
169
 
170
+ # Plot number of persons detected over frames
171
  fig, ax = plt.subplots(figsize=(10, 5))
172
  ax.plot(range(len(frame_emotions)), [len(emotions) for emotions in frame_emotions], label='Number of Persons Detected')
173
  ax.set_xlabel('Frame')
 
177
 
178
  st.pyplot(fig)
179
 
180
+ # Plot emotions over frames, using the same frame index
181
+ fig, ax = plt.subplots(figsize=(10, 5))
182
+ for emotion in frame_emotions_refined[0]:
183
+ ax.bar(range(len(frame_emotions_refined)), [emotion_counts[emotion] for emotion_counts in frame_emotions_refined], label=emotion)
184
+ ax.set_xlabel('Frame')
185
+ ax.set_ylabel('Emotion Count')
186
+ ax.set_title('Emotion Distribution Over Frames')
187
+ ax.legend()
188
+
189
+ st.pyplot(fig)
190
+
191
+
192
  else:
193
  st.error("Unsupported file type. Please upload an image or a video.")