reab5555 commited on
Commit
320dc6d
·
verified ·
1 Parent(s): 8ad22bc

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +8 -30
visualization.py CHANGED
@@ -217,12 +217,18 @@ def plot_posture(df, posture_scores, color='blue', anomaly_threshold=3):
217
  plt.close()
218
  return fig
219
 
220
-
221
  def filter_mse_for_most_frequent_person(df, mse_embeddings, mse_posture, mse_voice, most_frequent_person_frames):
222
  # Ensure most_frequent_person_frames is a list
223
  if not isinstance(most_frequent_person_frames, (list, np.ndarray)):
224
  most_frequent_person_frames = [most_frequent_person_frames]
225
 
 
 
 
 
 
 
 
226
  # Create a mask for the most frequent person frames
227
  mask = df['Frame'].isin(most_frequent_person_frames)
228
 
@@ -233,7 +239,6 @@ def filter_mse_for_most_frequent_person(df, mse_embeddings, mse_posture, mse_voi
233
 
234
  return mse_embeddings_filtered, mse_posture_filtered, mse_voice_filtered
235
 
236
-
237
  def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_voice, output_folder, desired_fps, most_frequent_person_frames):
238
  print(f"Creating heatmap video. Output folder: {output_folder}")
239
 
@@ -287,7 +292,7 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
287
  print(f"Failed to create heatmap video at: {heatmap_video_path}")
288
  return None
289
 
290
-
291
  def create_heatmap(t, mse_embeddings, mse_posture, mse_voice, video_fps, total_frames, video_width):
292
  frame_count = int(t * video_fps)
293
 
@@ -317,34 +322,7 @@ def create_heatmap(t, mse_embeddings, mse_posture, mse_voice, video_fps, total_f
317
  heatmap_img = heatmap_img.reshape(canvas.get_width_height()[::-1] + (3,))
318
  plt.close(fig)
319
  return heatmap_img
320
-
321
- def combine_video_and_heatmap(t):
322
- video_frame = video.get_frame(t)
323
- heatmap_frame = create_heatmap(t, mse_embeddings, mse_posture, mse_voice, video.fps, total_frames, width)
324
- heatmap_frame_resized = cv2.resize(heatmap_frame, (width, heatmap_frame.shape[0]))
325
- combined_frame = np.vstack((video_frame, heatmap_frame_resized))
326
- return combined_frame
327
-
328
- final_clip = VideoClip(combine_video_and_heatmap, duration=video.duration)
329
- final_clip = final_clip.set_audio(video.audio)
330
-
331
- # Write the final video
332
- final_clip.write_videofile(heatmap_video_path, codec='libx264', audio_codec='aac', fps=video.fps)
333
-
334
- # Close the video clips
335
- video.close()
336
- final_clip.close()
337
-
338
- if os.path.exists(heatmap_video_path):
339
- print(f"Heatmap video created at: {heatmap_video_path}")
340
- print(f"Heatmap video size: {os.path.getsize(heatmap_video_path)} bytes")
341
- return heatmap_video_path
342
- else:
343
- print(f"Failed to create heatmap video at: {heatmap_video_path}")
344
- return None
345
-
346
 
347
- # Function to create the correlation heatmap
348
  def plot_correlation_heatmap(mse_embeddings, mse_posture, mse_voice):
349
  data = np.vstack((mse_embeddings, mse_posture, mse_voice)).T
350
  df = pd.DataFrame(data, columns=["Facial Features", "Body Posture", "Voice"])
 
217
  plt.close()
218
  return fig
219
 
 
220
  def filter_mse_for_most_frequent_person(df, mse_embeddings, mse_posture, mse_voice, most_frequent_person_frames):
221
  # Ensure most_frequent_person_frames is a list
222
  if not isinstance(most_frequent_person_frames, (list, np.ndarray)):
223
  most_frequent_person_frames = [most_frequent_person_frames]
224
 
225
+ # Ensure df and mse arrays have the same length
226
+ min_length = min(len(df), len(mse_embeddings), len(mse_posture), len(mse_voice))
227
+ df = df.iloc[:min_length].copy()
228
+ mse_embeddings = mse_embeddings[:min_length]
229
+ mse_posture = mse_posture[:min_length]
230
+ mse_voice = mse_voice[:min_length]
231
+
232
  # Create a mask for the most frequent person frames
233
  mask = df['Frame'].isin(most_frequent_person_frames)
234
 
 
239
 
240
  return mse_embeddings_filtered, mse_posture_filtered, mse_voice_filtered
241
 
 
242
  def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_voice, output_folder, desired_fps, most_frequent_person_frames):
243
  print(f"Creating heatmap video. Output folder: {output_folder}")
244
 
 
292
  print(f"Failed to create heatmap video at: {heatmap_video_path}")
293
  return None
294
 
295
+ # Define the create_heatmap function
296
  def create_heatmap(t, mse_embeddings, mse_posture, mse_voice, video_fps, total_frames, video_width):
297
  frame_count = int(t * video_fps)
298
 
 
322
  heatmap_img = heatmap_img.reshape(canvas.get_width_height()[::-1] + (3,))
323
  plt.close(fig)
324
  return heatmap_img
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
 
326
  def plot_correlation_heatmap(mse_embeddings, mse_posture, mse_voice):
327
  data = np.vstack((mse_embeddings, mse_posture, mse_voice)).T
328
  df = pd.DataFrame(data, columns=["Facial Features", "Body Posture", "Voice"])