GullyDRS / gully_drs_core /replay_utils.py
AjaykumarPilla's picture
Update gully_drs_core/replay_utils.py
c62a88a verified
raw
history blame
1.7 kB
# gully_drs_core/replay_utils.py
import cv2
def generate_replay(
frames,
ball_path,
bounce_point,
impact_point,
decision,
stump_zone,
output_path='output.mp4',
fps=30
):
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
height, width = frames[0].shape[:2]
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
for i, frame in enumerate(frames):
# Draw ball trajectory
if i < len(ball_path):
for j in range(1, i):
if j < len(ball_path):
pt1 = ball_path[j-1]
pt2 = ball_path[j]
cv2.line(frame, pt1, pt2, (0, 0, 255), 2)
# Draw bounce point
if bounce_point:
cv2.circle(frame, bounce_point, 8, (255, 255, 0), -1)
cv2.putText(frame, "Bounce", (bounce_point[0]+5, bounce_point[1]-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 0), 1)
# Draw impact point
if impact_point:
cv2.circle(frame, impact_point, 8, (0, 255, 255), -1)
cv2.putText(frame, "Impact", (impact_point[0]+5, impact_point[1]-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 1)
# Draw stump zone
x1, y1, x2, y2 = stump_zone
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
# Show decision at top
cv2.putText(
frame,
f"Decision: {decision}",
(20, 40),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0, 255, 0) if decision == "NOT OUT" else (0, 0, 255),
2
)
out.write(frame)
out.release()
return output_path