Skip to content
christopherhehehePublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Robo Ref — Pushing for Unbiased Refereeing

AI Video Assistant Referee: a hackathon MVP that adjudicates tackles (foul or play on) from real match footage with a three-tier pipeline:

Tier Name What it does
1 The Watcher (CV) YOLOv8 + ByteTrack extracts every player, the ball, torso jersey colors, and camera motion; stitches fragmented tracks back together and picks the two players actually contesting the ball (instant cached coordinate maps when the model is off)
2 The Thinker (heuristics) Ball-anchored contact detection, pre-challenge possession, and did-the-defender-play-the-ball analysis; aggregates telemetry JSON
3 The Speaker (LLM) Gemini renders a formal two-sentence FIFA VAR ruling grounded in Law 12 (deterministic template fallback when no API key)

Supported input: slow-motion close-up replays of the tackle. Live wide-angle broadcast footage is too noisy for reliable box tracking (tiny ball, dozens of players, fast pans) — feed the app the replay, exactly as a human VAR would review it. Validated against 5 labeled real broadcast slo-mo clips: 5/5 correct verdicts.

Quick start

One-time setup (Python 3.10+, Node 18+):

cd backend
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
cd ../frontend && npm install

(Optional: backend/.venv/bin/python backend/scripts/generate_clips.py regenerates the synthetic mock-mode data in backend/mock_data/ — the JSONs are committed, so a fresh clone works without it.)

Then start / stop everything from the repo root:

./start.sh                           # backend :8000 + frontend :5173 (instant demo mode)
./stop.sh                            # stop both

POCKETVAR_FORCE_MOCK=0 ./start.sh    # real YOLO inference on uploads
export GEMINI_API_KEY="AIza..."      # set before ./start.sh for real Gemini rulings

Open http://localhost:5173. Logs stream to logs/backend.log and logs/frontend.log. (Manual alternative: cd backend && .venv/bin/uvicorn app:app --reload --port 8000 in one terminal, cd frontend && npm run dev in another; Ctrl+C stops each.)

Demo flow

  1. Live VAR Room — drag a slow-motion close-up replay of a tackle into the drop zone, optionally state the two jersey colors and the challenge location, and hit Initiate VAR Check. You get back the annotated video (player boxes + ball drawn server-side), the telemetry sheet, the flashing verdict, and the AI referee's ruling. Repeat uploads of a clip the model has already analyzed return in seconds (results are cached by file content in backend/uploads_cache/).
  2. Popular Decisions — three real World Cup 2026 tackles analyzed by the actual pipeline (backend/popular_cards.json), with annotated clip playback, metric logs, verdict badges, and fan voting.

Analyzing real match clips

The Watcher runs genuine YOLOv8 + ByteTrack on real footage (weights live in backend/models/yolov8n.pt). Use slow-motion close-up replays of the challenge — that is the supported input class:

  • All distances are in body-heights (zoom-invariant) and all time windows scale with fps (playback-speed-invariant) — a slo-mo replay is effectively a pre-slowed input with real pixels, which is exactly what the tracker needs. (A post-hoc "slow it down for YOLO" stage via optical-flow frame interpolation exists behind SLOW_FACTOR but measured worse — 5/5 → 1/5 on the eval set — because synthetic-frame artifacts corrupt tracker state; it ships disabled.)
  • Track stitching: ByteTrack drops player IDs during the tackle occlusion itself; fragments are re-joined by time/space/shirt-color and the gap is bridged, so the principals survive the collision.
  • Ball trajectory: per-frame ball candidates are filtered into one coherent speed-gated path (a single best-confidence detection flip-flops onto false positives and teleports).
  • Pair selection: the attacker/defender pair is the one that is tight together and on the ball at the same moment, matched to your stated jersey colors; every other tracked player is drawn as a thin gray box.
  • Global camera pan is estimated from background optical flow (velocity metrics are informational only — never decisive).

To analyze a clip offline and get a ready-to-hardcode Popular Decisions card:

cd backend
.venv/bin/python scripts/analyze_real_clip.py path/to/clip.mp4 \
  --teams "France vs Croatia" --phase "World Cup Final" --time "38'" \
  --attacker-color blue --defender-color "#c8102e"

Jersey colors identify which tracked player is the attacker vs the defender (kit names like red, white, sky blue, or #rrggbb hex). Omit both and the player covering more ground is treated as the attacker.

For close-ups where the penalty box lines aren't in frame, add --assume-in-area / --assume-out-of-area, or pass an explicit --penalty-area x1,y1,x2,y2 (normalized). The script prints the telemetry, the FALLBACK_DECISIONS card for PopularGrid.jsx, and writes the clip plus an annotated preview into frontend/public/assets/popular_clips/.

Configuration

Env var Effect
GEMINI_API_KEY Enables real Gemini rulings (gemini-2.0-flash, 3 s timeout). Unset → deterministic template rulings; the demo never blocks on the cloud.
POCKETVAR_FORCE_MOCK=1 Skips real YOLO inference in the API and serves cached coordinate maps — guarantees sub-3-second responses during live judging.

Decision rule

FOUL  ⇔  ball-anchored contact
         ∧ the attacker had the ball going into the challenge
         ∧ the defender did NOT play the ball
  • Contact only counts near the ball — overlapping boxes far from it are 2D-projection artifacts, not challenges. A challenge is a duel interval (the contiguous overlap run around the IoU peak, capped at ±0.9 s): possession is judged before it starts, the outcome after it ends.
  • Possession is strict and relative: the attacker must be at the ball (≤ 0.6 body-heights) and clearly closer than the defender for ≥ 40 % of the pre-challenge window. A defender shielding the ball, a 50-50, or a loose ball is not attacker possession — and without positive possession evidence the verdict is PLAY ON (contact alone is never a foul).
  • Defender played the ball is caught two ways: a distinct first touch before contact with confirmed possession transfer, or emerging with the ball once the duel separates.
  • Location never changes the verdict — it only selects the sanction (penalty kick inside the box, direct free kick otherwise; state it via the UI's "Challenge location" selector or the in_area form field).

Thresholds are class constants on Thinker in backend/rules_engine.py. Known limit: a live-speed 50-50 ball arrival is below what box-level heuristics can resolve — like a human referee, the system needs the slow-motion view for who-touched-first (the eval's cross-view report flags exactly these cases).

Evaluating & tuning on labeled clips

Drop real clips into backend/eval_clips/ and describe them in labels.json (see labels.example.json): expected verdict, both jersey colors, and an incident name shared by the live and slo-mo views of the same tackle. Then:

cd backend
.venv/bin/python scripts/evaluate.py             # accuracy table + cross-view consistency
.venv/bin/python scripts/evaluate.py --render    # + annotated videos in eval_clips/annotated/
.venv/bin/python scripts/inspect_tracks.py <clip-stem> [att_color def_color]  # track/color dump
.venv/bin/python scripts/debug_clip.py <clip-stem> <att_color> <def_color>    # telemetry timeline + key frames

The expensive YOLO pass is cached per clip (eval_clips/.cache/), so threshold and label changes re-score in seconds; pass --fresh after changing the detection stage itself.

To ground rulings in the Laws of the Game, paste the relevant excerpts (Law 12) into backend/fifa_laws.md — they are inlined into the Speaker's Gemini system prompt automatically.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages