File size: 784 Bytes
8bea2ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""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