Spaces:
Sleeping
Sleeping
Update visualizer.py
Browse files- visualizer.py +30 -39
visualizer.py
CHANGED
@@ -1,50 +1,41 @@
|
|
|
|
1 |
import cv2
|
2 |
-
import numpy as np
|
3 |
-
import tempfile
|
4 |
import os
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
cv2.line(frame, (x, pitch_y), (x, pitch_y - 60), (255, 255, 255), 2)
|
9 |
-
cv2.line(frame, (stump_zone[0] - 40, pitch_y), (stump_zone[1] + 40, pitch_y), (255, 255, 255), 2)
|
10 |
|
11 |
-
def
|
12 |
-
|
13 |
-
|
14 |
-
cv2.circle(frame, (int(x), int(y)), 5, (0, 255, 0), -1)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
cv2.putText(frame, f"Decision: {decision}", (30, 50),
|
19 |
-
cv2.FONT_HERSHEY_SIMPLEX, 1.5, color, 3)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
trajectory = prediction_data["trajectory_points"]
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
draw_trajectory(frame_copy, trajectory[:idx + 1])
|
40 |
-
else:
|
41 |
-
draw_trajectory(frame_copy, trajectory)
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
out.release()
|
50 |
-
return output_path, decision
|
|
|
1 |
+
# visualizer.py
|
2 |
import cv2
|
|
|
|
|
3 |
import os
|
4 |
+
import uuid
|
5 |
+
from utils import save_video
|
6 |
|
7 |
+
OUTPUT_DIR = "output_videos"
|
8 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
|
9 |
|
10 |
+
def draw_visuals(frames, ball_positions, trajectory, impact_frame_idx, decision):
|
11 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
12 |
+
output_frames = []
|
|
|
13 |
|
14 |
+
for i, frame in enumerate(frames):
|
15 |
+
frame_draw = frame.copy()
|
|
|
|
|
16 |
|
17 |
+
# Draw past ball positions
|
18 |
+
for _, x, y in ball_positions:
|
19 |
+
cv2.circle(frame_draw, (x, y), 5, (0, 255, 255), -1)
|
|
|
20 |
|
21 |
+
# Draw trajectory after impact
|
22 |
+
if i == impact_frame_idx:
|
23 |
+
for x, y in trajectory:
|
24 |
+
cv2.circle(frame_draw, (x, y), 4, (0, 0, 255), -1)
|
25 |
|
26 |
+
# Highlight impact frame
|
27 |
+
if i == impact_frame_idx:
|
28 |
+
cv2.putText(frame_draw, "IMPACT!", (50, 50), font, 1.0, (0, 0, 255), 2)
|
29 |
+
cv2.rectangle(frame_draw, (10, 10), (630, 470), (0, 0, 255), 4)
|
30 |
|
31 |
+
# Final decision on last frame
|
32 |
+
if i == len(frames) - 1:
|
33 |
+
cv2.putText(frame_draw, f"Decision: {decision}", (100, 420), font, 1.2, (255, 0, 0), 3)
|
34 |
|
35 |
+
output_frames.append(frame_draw)
|
|
|
|
|
|
|
36 |
|
37 |
+
# Save annotated video
|
38 |
+
video_id = str(uuid.uuid4())
|
39 |
+
out_path = os.path.join(OUTPUT_DIR, f"{video_id}_annotated.mp4")
|
40 |
+
save_video(output_frames, out_path)
|
41 |
+
return out_path
|
|
|
|
|
|