Turn single-camera TV broadcasts into metric player/ball trajectories and football insights (distance, speed zones, heatmaps, possession proxy, formations, roles).
The pipeline runs frame-by-frame, with class-aware tracking, jersey OCR, and per-frame homographies from PnLCalib.
- Detection: Domain-adapted YOLOv8 (players, goalkeeper, main ref, side ref, ball, others).
- Class-aware tracking: BoT-SORT for people (optional ReID on GPU), BoostTrack for the ball.
- Team clustering: Simple K-Means on jersey colors with periodic refits.
- Jersey OCR: PARSeq with a legibility gate and temporal voting for stable shirt numbers.
- Calibration: PnLCalib keypoint/line nets → per-frame homography (H_t) + stability gate.
- Mapping: Apply (H_t^{-1}) to foot points → metric pitch (105×68 m).
- Analytics: Distance & speed zones, positional heatmaps, possession measuring, formations, event detection.
pip install -r requirements.txtDownload: YOLOv8n Detection Model
Download: PARSeq_tiny Jersey OCR model
Download: Resnet34 Player crop Legibility Classifier (Origin-Repo)
Download: PnLCalib Keypoint Recognizer (Origin-Repo)
Download: PnLCalib Line Recognizer (Origin-Repo)
python -m tracking_pipeline.main \
path/to/input_video.mp4Outputs
-
Video preview with overlays:
output/..._output_video.mp4 -
Per-frame YOLO labels (optional):
outputDet/<seq>/labels/000001.txt -
Tracking CSV (MOT-like w/ jersey):
frame,id,x,y,w,h,conf,class,jersey
classis a string label (e.g.,'L'/'R'for teams,'2'ball,'3'ref, …)- jersey
-1means unknown
cd PnLCalib
python inference_modified.py \
--weights_kp weights/hrnetv2_w48_kp.pth \
--weights_line weights/hrnetv2_w48_line.pth \
--input_path path/to/input.mp4 \
--input_type video \
--device cuda:0 \
--batch_size 8 \Output
-
Homographies CSV with rows:
frame,H00,H01,H02,H10,H11,H12,H20,H21,H22
cd PnLCalib
python transformandplotsmooth_modified.py \
--video path/to/input.mp4 \
--tracking path/to/tracking_results.txt \
--transforms_csv output/homographies.csv \
--output_video output/overlay.mp4 \
--output_csv output/coords.csvOutputs
-
Overlay video with a drawn pitch and 2D points
-
2D CSV:
frame,id,model_x,model_y,class,jersey
where
model_x/yare in meters on a 105×68 m pitch.
Open Analysis.ipynb and point it to the 2D CSV to compute:
- distance & speed zones,
- positional heatmaps,
- possession/pass proxy (nearest-player rule to ball),
- formation & role clustering,
- simple event timeline.
