Update visualization.py
Browse files- visualization.py +33 -32
visualization.py
CHANGED
@@ -271,39 +271,39 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
271 |
ax.set_xticks([])
|
272 |
plt.tight_layout()
|
273 |
|
274 |
-
if progress:
|
275 |
-
progress(0, desc="Generating video with heatmap")
|
276 |
-
|
277 |
line = None
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
|
|
|
|
|
|
307 |
except Exception as e:
|
308 |
print(f"Error in frame processing: {str(e)}")
|
309 |
import traceback
|
@@ -315,6 +315,7 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
315 |
|
316 |
if os.path.exists(heatmap_video_path):
|
317 |
print(f"Heatmap video created at: {heatmap_video_path}")
|
|
|
318 |
return heatmap_video_path
|
319 |
else:
|
320 |
print(f"Failed to create heatmap video at: {heatmap_video_path}")
|
|
|
271 |
ax.set_xticks([])
|
272 |
plt.tight_layout()
|
273 |
|
|
|
|
|
|
|
274 |
line = None
|
275 |
+
try:
|
276 |
+
for frame_count in range(total_frames):
|
277 |
+
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_count)
|
278 |
+
ret, frame = cap.read()
|
279 |
+
if not ret:
|
280 |
+
print(f"Failed to read frame {frame_count}")
|
281 |
+
break
|
282 |
+
|
283 |
+
if line:
|
284 |
+
line.remove()
|
285 |
+
line = ax.axvline(x=frame_count, color='r', linewidth=2)
|
286 |
+
|
287 |
+
canvas = FigureCanvasAgg(fig)
|
288 |
+
canvas.draw()
|
289 |
+
heatmap_img = np.frombuffer(canvas.tostring_rgb(), dtype='uint8')
|
290 |
+
heatmap_img = heatmap_img.reshape(canvas.get_width_height()[::-1] + (3,))
|
291 |
+
heatmap_img = cv2.resize(heatmap_img, (width, 200))
|
292 |
+
|
293 |
+
combined_frame = np.vstack((frame, heatmap_img))
|
294 |
+
|
295 |
+
seconds = frame_count / original_fps
|
296 |
+
timecode = f"{int(seconds//3600):02d}:{int((seconds%3600)//60):02d}:{int(seconds%60):02d}"
|
297 |
+
cv2.putText(combined_frame, f"Time: {timecode}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
|
298 |
+
|
299 |
+
out.write(combined_frame)
|
300 |
+
|
301 |
+
if progress is not None:
|
302 |
+
try:
|
303 |
+
progress((frame_count + 1) / total_frames, desc="Generating video with heatmap")
|
304 |
+
except Exception as e:
|
305 |
+
print(f"Error updating progress: {str(e)}")
|
306 |
+
|
307 |
except Exception as e:
|
308 |
print(f"Error in frame processing: {str(e)}")
|
309 |
import traceback
|
|
|
315 |
|
316 |
if os.path.exists(heatmap_video_path):
|
317 |
print(f"Heatmap video created at: {heatmap_video_path}")
|
318 |
+
print(f"Heatmap video size: {os.path.getsize(heatmap_video_path)} bytes")
|
319 |
return heatmap_video_path
|
320 |
else:
|
321 |
print(f"Failed to create heatmap video at: {heatmap_video_path}")
|