Spaces:
Sleeping
Sleeping
Update gully_drs_core/replay_utils.py
Browse files
gully_drs_core/replay_utils.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
# gully_drs_core/replay_utils.py
|
| 2 |
-
|
| 3 |
import cv2
|
|
|
|
| 4 |
|
| 5 |
def generate_replay(
|
| 6 |
frames,
|
|
@@ -9,15 +8,22 @@ def generate_replay(
|
|
| 9 |
impact_point,
|
| 10 |
decision,
|
| 11 |
stump_zone,
|
|
|
|
| 12 |
output_path='output.mp4',
|
| 13 |
fps=30
|
| 14 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 16 |
-
height, width = frames[0].shape[:2]
|
| 17 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 18 |
|
| 19 |
for i, frame in enumerate(frames):
|
| 20 |
-
# Draw ball trajectory
|
| 21 |
if i < len(ball_path):
|
| 22 |
for j in range(1, i):
|
| 23 |
if j < len(ball_path):
|
|
@@ -25,23 +31,19 @@ def generate_replay(
|
|
| 25 |
pt2 = ball_path[j]
|
| 26 |
cv2.line(frame, pt1, pt2, (0, 0, 255), 2)
|
| 27 |
|
| 28 |
-
# Draw bounce point
|
| 29 |
if bounce_point:
|
| 30 |
cv2.circle(frame, bounce_point, 8, (255, 255, 0), -1)
|
| 31 |
cv2.putText(frame, "Bounce", (bounce_point[0]+5, bounce_point[1]-10),
|
| 32 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 0), 1)
|
| 33 |
|
| 34 |
-
# Draw impact point
|
| 35 |
if impact_point:
|
| 36 |
cv2.circle(frame, impact_point, 8, (0, 255, 255), -1)
|
| 37 |
cv2.putText(frame, "Impact", (impact_point[0]+5, impact_point[1]-10),
|
| 38 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 1)
|
| 39 |
|
| 40 |
-
# Draw stump zone
|
| 41 |
x1, y1, x2, y2 = stump_zone
|
| 42 |
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
|
| 43 |
|
| 44 |
-
# Show decision at top
|
| 45 |
cv2.putText(
|
| 46 |
frame,
|
| 47 |
f"Decision: {decision}",
|
|
@@ -52,6 +54,16 @@ def generate_replay(
|
|
| 52 |
2
|
| 53 |
)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
out.write(frame)
|
| 56 |
|
| 57 |
out.release()
|
|
|
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
def generate_replay(
|
| 5 |
frames,
|
|
|
|
| 8 |
impact_point,
|
| 9 |
decision,
|
| 10 |
stump_zone,
|
| 11 |
+
speed_kmh,
|
| 12 |
output_path='output.mp4',
|
| 13 |
fps=30
|
| 14 |
):
|
| 15 |
+
if not frames or not ball_path:
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
sample = next((f for f in frames if f is not None), None)
|
| 19 |
+
if sample is None:
|
| 20 |
+
return None
|
| 21 |
+
|
| 22 |
+
height, width = sample.shape[:2]
|
| 23 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
|
|
|
| 24 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 25 |
|
| 26 |
for i, frame in enumerate(frames):
|
|
|
|
| 27 |
if i < len(ball_path):
|
| 28 |
for j in range(1, i):
|
| 29 |
if j < len(ball_path):
|
|
|
|
| 31 |
pt2 = ball_path[j]
|
| 32 |
cv2.line(frame, pt1, pt2, (0, 0, 255), 2)
|
| 33 |
|
|
|
|
| 34 |
if bounce_point:
|
| 35 |
cv2.circle(frame, bounce_point, 8, (255, 255, 0), -1)
|
| 36 |
cv2.putText(frame, "Bounce", (bounce_point[0]+5, bounce_point[1]-10),
|
| 37 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 0), 1)
|
| 38 |
|
|
|
|
| 39 |
if impact_point:
|
| 40 |
cv2.circle(frame, impact_point, 8, (0, 255, 255), -1)
|
| 41 |
cv2.putText(frame, "Impact", (impact_point[0]+5, impact_point[1]-10),
|
| 42 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 1)
|
| 43 |
|
|
|
|
| 44 |
x1, y1, x2, y2 = stump_zone
|
| 45 |
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
|
| 46 |
|
|
|
|
| 47 |
cv2.putText(
|
| 48 |
frame,
|
| 49 |
f"Decision: {decision}",
|
|
|
|
| 54 |
2
|
| 55 |
)
|
| 56 |
|
| 57 |
+
cv2.putText(
|
| 58 |
+
frame,
|
| 59 |
+
f"Speed: {speed_kmh} km/h",
|
| 60 |
+
(20, 75),
|
| 61 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 62 |
+
0.9,
|
| 63 |
+
(255, 255, 255),
|
| 64 |
+
2
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
out.write(frame)
|
| 68 |
|
| 69 |
out.release()
|