Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +11 -11
visualization.py
CHANGED
|
@@ -270,34 +270,34 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
| 270 |
os.makedirs(output_folder, exist_ok=True)
|
| 271 |
|
| 272 |
output_filename = os.path.basename(video_path).rsplit('.', 1)[0] + '_heatmap.mp4'
|
| 273 |
-
heatmap_video_path
|
| 274 |
|
| 275 |
print(f"Heatmap video will be saved at: {heatmap_video_path}")
|
| 276 |
|
| 277 |
# Load the original video
|
| 278 |
-
video
|
| 279 |
|
| 280 |
# Get video properties
|
| 281 |
width, height is video.w, video.h
|
| 282 |
total_frames is int(video.duration * video.fps)
|
| 283 |
|
| 284 |
# Ensure all MSE arrays have the same length as total_frames
|
| 285 |
-
mse_embeddings
|
| 286 |
np.arange(len(mse_embeddings)), mse_embeddings)
|
| 287 |
-
mse_posture
|
| 288 |
np.arange(len(mse_posture)), mse_posture)
|
| 289 |
-
mse_voice
|
| 290 |
np.arange(len(mse_voice)), mse_voice)
|
| 291 |
|
| 292 |
def combine_video_and_heatmap(t):
|
| 293 |
-
video_frame
|
| 294 |
-
heatmap_frame
|
| 295 |
-
heatmap_frame_resized
|
| 296 |
-
combined_frame
|
| 297 |
return combined_frame
|
| 298 |
|
| 299 |
-
final_clip
|
| 300 |
-
final_clip
|
| 301 |
|
| 302 |
# Write the final video
|
| 303 |
final_clip.write_videofile(heatmap_video_path, codec='libx264', audio_codec='aac', fps=video.fps)
|
|
|
|
| 270 |
os.makedirs(output_folder, exist_ok=True)
|
| 271 |
|
| 272 |
output_filename = os.path.basename(video_path).rsplit('.', 1)[0] + '_heatmap.mp4'
|
| 273 |
+
heatmap_video_path = os.path.join(output_folder, output_filename)
|
| 274 |
|
| 275 |
print(f"Heatmap video will be saved at: {heatmap_video_path}")
|
| 276 |
|
| 277 |
# Load the original video
|
| 278 |
+
video = VideoFileClip(video_path)
|
| 279 |
|
| 280 |
# Get video properties
|
| 281 |
width, height is video.w, video.h
|
| 282 |
total_frames is int(video.duration * video.fps)
|
| 283 |
|
| 284 |
# Ensure all MSE arrays have the same length as total_frames
|
| 285 |
+
mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
|
| 286 |
np.arange(len(mse_embeddings)), mse_embeddings)
|
| 287 |
+
mse_posture = np.interp(np.linspace(0, len(mse_posture) - 1, total_frames),
|
| 288 |
np.arange(len(mse_posture)), mse_posture)
|
| 289 |
+
mse_voice = np.interp(np.linspace(0, len(mse_voice) - 1, total_frames),
|
| 290 |
np.arange(len(mse_voice)), mse_voice)
|
| 291 |
|
| 292 |
def combine_video_and_heatmap(t):
|
| 293 |
+
video_frame = video.get_frame(t)
|
| 294 |
+
heatmap_frame = create_heatmap(t, mse_embeddings, mse_posture, mse_voice, video.fps, total_frames, width, largest_cluster)
|
| 295 |
+
heatmap_frame_resized = cv2.resize(heatmap_frame, (width, heatmap_frame.shape[0]))
|
| 296 |
+
combined_frame = np.vstack((video_frame, heatmap_frame_resized))
|
| 297 |
return combined_frame
|
| 298 |
|
| 299 |
+
final_clip = VideoClip(combine_video_and_heatmap, duration=video.duration)
|
| 300 |
+
final_clip = final_clip.set_audio(video.audio)
|
| 301 |
|
| 302 |
# Write the final video
|
| 303 |
final_clip.write_videofile(heatmap_video_path, codec='libx264', audio_codec='aac', fps=video.fps)
|