CourtVision Stack is a production-style project for end-to-end basketball analytics. It uses a structured repo with configs, scripts, and modular code so a cloned copy can install dependencies, download assets, and run inference end to end.
- Player detection with RF-DETR
- SAM2 mask-based tracking across video
- Team clustering from jersey colors
- Jersey number OCR with validation
- Court keypoint detection and coordinate mapping
- Shot event detection (jump shot, layup/dunk, ball-in-basket)
courtvision-stack/
assets/
fonts/
examples/
configs/
default.yaml
rosters.yaml
data/
raw/videos/
raw/rosters/
interim/frames/
processed/
models/
sam2/
outputs/
detections/
tracks/
teams/
ocr/
court/
shots/
scripts/
download_assets.py
download_assets.ps1
download_assets.sh
setup_env.ps1
setup_env.sh
run_pipeline.ps1
run_pipeline.sh
src/
detection/
tracking/
team/
ocr/
court/
shots/
utils/
config.py
pipeline.py
-
Copy the environment file and set your Roboflow key:
copy .env.example .env(Windows)cp .env.example .env(macOS/Linux)
-
Install dependencies:
- Windows:
scripts\setup_env.ps1 - macOS/Linux:
bash scripts/setup_env.sh
- Windows:
-
Download assets, sample videos, and SAM2 checkpoint:
- Windows:
scripts\download_assets.ps1 - macOS/Linux:
bash scripts/download_assets.sh
- Windows:
-
Install SAM2 after the repo is downloaded:
python -m pip install -e models/sam2/segment-anything-2-real-time
-
Run the pipeline:
- Windows:
scripts\run_pipeline.ps1 --step all - macOS/Linux:
bash scripts/run_pipeline.sh --step all
- Windows:
- detection:
outputs/detections/<video>-detection.mp4 - tracking:
outputs/tracks/<video>-mask.mp4 - teams:
outputs/teams/<video>-teams.mp4 - ocr:
outputs/ocr/<video>-validated-numbers.mp4 - court:
outputs/court/<video>-map.mp4 - shots:
outputs/shots/shot_events.jsonl
configs/default.yamlcontrols model IDs, thresholds, and paths.configs/rosters.yamlstores team rosters and colors.
- Heavy files are not stored in the repo. The download script fetches SAM2 weights, fonts, and sample videos when you run it.
inference-gpurequires a CUDA-capable GPU. For CPU-only machines, replace it withinferenceinrequirements.txt.ffmpegis required for optional video compression; install it if needed.
- SAM2: https://github.com/facebookresearch/sam2
- Real-time SAM2: https://github.com/Gy920/segment-anything-2-real-time
- Roboflow Sports: https://github.com/roboflow/sports