Spaces:
Sleeping
Sleeping
"""Simple ByteTrack‑style tracker for the cricket ball.""" | |
import math | |
from typing import List, Dict | |
# Placeholder minimal tracker (replace with ByteTrack/SORT lib) | |
class BasicBallTracker: | |
def __init__(self): | |
self.track = [] # list of (frame_idx, x_center, y_center) | |
def update(self, detections: List[Dict], frame_idx: int): | |
"""Select the highest‑confidence 'ball' bbox each frame.""" | |
balls = [d for d in detections if d["class"] == "ball"] | |
if not balls: | |
return None | |
best = max(balls, key=lambda d: d["conf"]) | |
x1, y1, x2, y2 = best["bbox"] | |
xc, yc = (x1 + x2) / 2, (y1 + y2) / 2 | |
self.track.append((frame_idx, xc, yc)) | |
return xc, yc | |
def get_track(self): | |
return self.track |