Update visualization.py
Browse files- 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 *
|
275 |
|
276 |
-
# Ensure MSE arrays
|
277 |
-
def
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
|
|
285 |
|
286 |
def combine_video_and_heatmap(t):
|
287 |
-
|
288 |
-
video_frame = video.get_frame(
|
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)))
|