Skip to content
Manish Maurya

Computer vision · Detection and tracking

Basketball Video Analytics

A computer vision pipeline that detects and tracks players and the ball in game footage, assigns teams, estimates possession, passes and interceptions, and projects players onto a top-down tactical court.

  • Python
  • Ultralytics YOLO
  • ByteTrack
  • Fashion-CLIP
  • OpenCV
  • Docker

Built on the open-source abdullahtarek/basketball_analysis project. Reused code, model weights and datasets remain subject to their original licenses.

Overview

The pipeline takes a basketball video and produces an annotated version: players and the ball are detected and tracked, players are split into teams, possession, passes and interceptions are estimated, and a top-down court view shows where everyone is, with speed and distance for each player.

System architecture

Pipeline
Input video
  -> YOLO detection: players, ball and court keypoints
  -> ByteTrack player tracking
  -> Fashion-CLIP team assignment
  -> Ball possession estimation
       -> pass and interception estimates
  -> Court homography and top-down player positions
  -> Speed and distance estimates
  -> Annotated video with tactical view and statistics

Technical implementation

  • Detection and tracking: fine-tuned Ultralytics YOLO models detect players and the ball; ByteTrack, through the supervision library, keeps player IDs stable across frames.
  • Team assignment: a zero-shot Fashion-CLIP model groups players by jersey appearance, with no team-specific training.
  • Possession and events: possession comes from the ball's proximity to player bounding boxes; passes and interceptions are inferred from changes in possession and team.
  • Tactical view: court keypoint detection plus a homography projects positions onto a top-down court, which also gives speed in km/h and distance in metres.

Reliability work

  • Input validation

    Video loading checks that the input file exists and that OpenCV can open it before reading frames, and reports which check failed.

  • Memory on long videos

    Videos longer than 1,000 frames are subsampled while loading, so long clips don't hold every frame in memory.

  • Defensive drawing

    The overlay drawers handle missing or malformed per-frame data, such as frames with no players or no court keypoints, instead of raising.

  • Docker build

    Fixed the Docker build. The image installs the system libraries OpenCV needs and runs the pipeline with input and output folders mounted.

Limitations

  • Model weights aren't included in the repository; compatible weights must be added or trained with the provided notebooks.
  • Possession, passes and interceptions are estimates, not ground-truth event labels.
  • Speed and distance depend on the keypoint mapping and a nominal 28 m × 15 m court.
  • I haven't benchmarked accuracy or throughput, so this page doesn't quote any.