reab5555 commited on
Commit
a5d304e
·
verified ·
1 Parent(s): 30a22c3

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +13 -11
visualization.py CHANGED
@@ -271,21 +271,23 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
271
 
272
  # Get video properties
273
  width, height = video.w, video.h
274
- total_frames = int(video.duration * desired_fps)
275
 
276
- # Ensure MSE arrays have the same length as total_frames
277
- def pad_mse_array(mse_array, total_frames):
278
- if len(mse_array) < total_frames:
279
- return np.pad(mse_array, (0, total_frames - len(mse_array)), 'constant', constant_values=0)
280
- return mse_array[:total_frames]
 
281
 
282
- mse_embeddings = pad_mse_array(mse_embeddings, total_frames)
283
- mse_posture = pad_mse_array(mse_posture, total_frames)
284
- mse_voice = pad_mse_array(mse_voice, total_frames)
 
285
 
286
  def combine_video_and_heatmap(t):
287
- original_frame = int(t * video.fps)
288
- video_frame = video.get_frame(original_frame / video.fps)
289
 
290
  heatmap_frame = create_heatmap(t, mse_embeddings, mse_posture, mse_voice, desired_fps, total_frames, width)
291
  heatmap_frame_resized = cv2.resize(heatmap_frame, (width, int(height * 0.2)))
 
271
 
272
  # Get video properties
273
  width, height = video.w, video.h
274
+ total_frames = int(video.duration * video.fps)
275
 
276
+ # Ensure MSE arrays align with original video frames
277
+ def align_mse_array(mse_array, original_fps, desired_fps, total_frames):
278
+ original_times = np.arange(len(mse_array)) / original_fps
279
+ desired_times = np.arange(total_frames) / desired_fps
280
+ interpolated_mse = np.interp(desired_times, original_times, mse_array)
281
+ return interpolated_mse
282
 
283
+ original_fps = len(mse_embeddings) / video.duration
284
+ mse_embeddings = align_mse_array(mse_embeddings, original_fps, desired_fps, total_frames)
285
+ mse_posture = align_mse_array(mse_posture, original_fps, desired_fps, total_frames)
286
+ mse_voice = align_mse_array(mse_voice, original_fps, desired_fps, total_frames)
287
 
288
  def combine_video_and_heatmap(t):
289
+ frame_index = int(t * desired_fps)
290
+ video_frame = video.get_frame(t)
291
 
292
  heatmap_frame = create_heatmap(t, mse_embeddings, mse_posture, mse_voice, desired_fps, total_frames, width)
293
  heatmap_frame_resized = cv2.resize(heatmap_frame, (width, int(height * 0.2)))