Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +0 -41
visualization.py
CHANGED
|
@@ -269,44 +269,3 @@ def plot_stacked_mse_heatmaps(mse_face, mse_posture, mse_voice, df, title="Combi
|
|
| 269 |
plt.tight_layout()
|
| 270 |
plt.close()
|
| 271 |
return fig
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
def create_video_with_heatmap(video_path, mse_face, mse_posture, mse_voice, df, output_path):
|
| 275 |
-
# Load the original video
|
| 276 |
-
video = VideoFileClip(video_path)
|
| 277 |
-
|
| 278 |
-
# Create the stacked heatmap
|
| 279 |
-
fig = plot_stacked_mse_heatmaps(mse_face, mse_posture, mse_voice, df)
|
| 280 |
-
heatmap_img = mplfig_to_npimage(fig)
|
| 281 |
-
|
| 282 |
-
# Resize heatmap to match video width
|
| 283 |
-
heatmap_height = int(video.h * 0.2) # 20% of video height
|
| 284 |
-
heatmap_resized = cv2.resize(heatmap_img, (video.w, heatmap_height))
|
| 285 |
-
|
| 286 |
-
def make_frame(t):
|
| 287 |
-
# Get the current frame from the original video
|
| 288 |
-
frame = video.get_frame(t)
|
| 289 |
-
|
| 290 |
-
# Calculate the position of the vertical line
|
| 291 |
-
line_pos = int(t / video.duration * video.w)
|
| 292 |
-
|
| 293 |
-
# Add the vertical line to the heatmap only
|
| 294 |
-
heatmap_with_line = heatmap_resized.copy()
|
| 295 |
-
cv2.line(heatmap_with_line, (line_pos, 0), (line_pos, heatmap_height), (0, 0, 0), 2)
|
| 296 |
-
|
| 297 |
-
# Combine the original frame with the heatmap
|
| 298 |
-
combined_frame = np.vstack((frame, heatmap_with_line))
|
| 299 |
-
|
| 300 |
-
return combined_frame
|
| 301 |
-
|
| 302 |
-
# Create a new video clip with the combined frames
|
| 303 |
-
final_clip = VideoClip(make_frame, duration=video.duration)
|
| 304 |
-
|
| 305 |
-
# Write the final video
|
| 306 |
-
final_clip.write_videofile(output_path, codec='libx264', fps=video.fps)
|
| 307 |
-
|
| 308 |
-
# Close the clips
|
| 309 |
-
video.close()
|
| 310 |
-
final_clip.close()
|
| 311 |
-
|
| 312 |
-
return output_path
|
|
|
|
| 269 |
plt.tight_layout()
|
| 270 |
plt.close()
|
| 271 |
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|