Update visualization.py
Browse files- visualization.py +9 -8
visualization.py
CHANGED
@@ -278,7 +278,7 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
278 |
mse_posture = fill_with_previous_values(mse_posture, total_frames)
|
279 |
mse_voice = fill_with_previous_values(mse_voice, total_frames)
|
280 |
|
281 |
-
def create_heatmap(t, mse_embeddings, mse_posture, mse_voice, fps, total_frames, width):
|
282 |
frame_index = int(t * fps)
|
283 |
mse_face = mse_embeddings[frame_index]
|
284 |
mse_body = mse_posture[frame_index]
|
@@ -293,17 +293,18 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
293 |
color = plt.cm.hot(normalized_value)
|
294 |
return (color[0] * 255, color[1] * 255, color[2] * 255) # Convert to RGB
|
295 |
|
296 |
-
heatmap_face = np.full((height
|
297 |
-
heatmap_body = np.full((height
|
298 |
-
heatmap_audio = np.full((height
|
299 |
|
300 |
-
|
301 |
-
|
|
|
302 |
|
303 |
def combine_video_and_heatmap(get_frame, t):
|
304 |
video_frame = get_frame(t)
|
305 |
-
heatmap_frame = create_heatmap(t, mse_embeddings, mse_posture, mse_voice, desired_fps, total_frames, width)
|
306 |
-
combined_frame =
|
307 |
return combined_frame
|
308 |
|
309 |
final_clip = video.fl(combine_video_and_heatmap)
|
|
|
278 |
mse_posture = fill_with_previous_values(mse_posture, total_frames)
|
279 |
mse_voice = fill_with_previous_values(mse_voice, total_frames)
|
280 |
|
281 |
+
def create_heatmap(t, mse_embeddings, mse_posture, mse_voice, fps, total_frames, width, height):
|
282 |
frame_index = int(t * fps)
|
283 |
mse_face = mse_embeddings[frame_index]
|
284 |
mse_body = mse_posture[frame_index]
|
|
|
293 |
color = plt.cm.hot(normalized_value)
|
294 |
return (color[0] * 255, color[1] * 255, color[2] * 255) # Convert to RGB
|
295 |
|
296 |
+
heatmap_face = np.full((height, width, 3), get_heatmap_color(mse_face, max_mse_face), dtype=np.uint8)
|
297 |
+
heatmap_body = np.full((height, width, 3), get_heatmap_color(mse_body, max_mse_body), dtype=np.uint8)
|
298 |
+
heatmap_audio = np.full((height, width, 3), get_heatmap_color(mse_audio, max_mse_audio), dtype=np.uint8)
|
299 |
|
300 |
+
# Combine heatmaps
|
301 |
+
combined_heatmap = (heatmap_face + heatmap_body + heatmap_audio) / 3
|
302 |
+
return combined_heatmap.astype(np.uint8)
|
303 |
|
304 |
def combine_video_and_heatmap(get_frame, t):
|
305 |
video_frame = get_frame(t)
|
306 |
+
heatmap_frame = create_heatmap(t, mse_embeddings, mse_posture, mse_voice, desired_fps, total_frames, width, height)
|
307 |
+
combined_frame = cv2.addWeighted(video_frame, 0.7, heatmap_frame, 0.3, 0)
|
308 |
return combined_frame
|
309 |
|
310 |
final_clip = video.fl(combine_video_and_heatmap)
|