Skip to content
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
aisutdPublic archive

About

AIM Fall 2026: NextRun — Basketball stat tracking application and community platform.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

NextRun

NextRun

AI stat tracking for pickup basketball.
Point a phone at the court. NextRun finds every player, follows the ball, and counts every basket — live.

Expo SDK 58 · React Native 0.88 · TypeScript · FastAPI · YOLO pose + ball/hoop models


Live detection: players tracked, ball ringed in yellow, hoop in orange, baskets and points counted

Live detection on a real court: each player boxed with a stable ID, the ball ringed in yellow, the hoop in orange, baskets and points counted as they happen.

What it does

🎥 Live scouting camera Stream the phone camera to the AI and watch players, poses, the ball, hoops, 2PT/3PT zones and baskets drawn on screen in real time. Stop the session and it is saved for full analysis.
📤 Upload a game Upload any game video. The full pipeline tracks every player, maps the court, and scores every shot, rebound, assist and point per player.
📊 Results dashboard Annotated replay video, box score, shot chart, scoring log with running score, and one-tap fixes for any call the AI got wrong.
👥 Teams Everyone the AI tracked is shown once, with a photo. Tap to put them on Team A or B and the stats re-run instantly.
🧠 Models tab Accuracy of every model on its test set, and inference speed measured on your machine.
🏆 The rest of the app Player cards, levels and XP, daily quests, titles, clubs, friends, game history and manual game logging.

How live tracking works

Phone (Expo Go)                                  Laptop (FastAPI backend)
───────────────                                  ────────────────────────
camera frame ── JPEG ──────────────────────────▶ pose model    → players + skeletons
                                                 ball/hoop     → ball, rims
                                                 focus pass    → second, zoomed look for the ball
                                                 trackers      → stable IDs, ball through occlusion
overlay ◀────── players, ball (+ speed), hoops ─ court + zones → 2PT / 3PT, who has the ball
                 baskets, score                  basket check  → made shots, points

The overlay is drawn where things are now, not where they were when the frame was grabbed. Each answer carries each player's and the ball's speed, so the phone moves them forward by the time that passed.

The ball stays on screen at all times:

  • Held: once it is seen in someone's hands, it moves with that player, even while their body hides it.
  • In the air: a shot or pass follows its gravity arc through frames where the ball is blurred or blocked.
  • Lost: it goes to the player nearest to where it was last seen, until it is seen again.
  • False balls are ignored: red shorts, blue or green jerseys, lamp posts, things far too big, and jumps across the court in a single frame.

Players stay on screen too:

  • Running players keep their ID: they are matched by where they are heading, not just by where they were.
  • Hidden players stay: someone behind another player is kept, drawn dashed, for up to 2.5 seconds.
  • Boxes follow the camera: they move with the picture when a hand-held phone pans.
  • No blinking boxes: a one-frame false detection never shows up.

Quick start

You need Node 20.19+, Python 3.10+, and the Expo Go app on your phone.

1. Backend (the AI)

git clone https://github.com/aisutd/nextrun.git
cd nextrun/backend
python3 scripts/download_weights.py          # the 4 AI models, ~165 MB, from the GitHub release
python3 -m venv ../.venv
../.venv/bin/pip install -e ".[detect,api]"
PYTHONPATH=src ../.venv/bin/python -m uvicorn nextrun_cv.api:app --host 0.0.0.0 --port 8000

The backend is ready when it prints Uvicorn running on http://0.0.0.0:8000. Open http://localhost:8000/docs to see every endpoint.

On Windows (PowerShell)
cd nextrun\backend
python scripts\download_weights.py
python -m venv ..\.venv
..\.venv\Scripts\pip install -e ".[detect,api]"
$env:PYTHONPATH="src"; ..\.venv\Scripts\python -m uvicorn nextrun_cv.api:app --host 0.0.0.0 --port 8000

The model weights are too big for git, so they live on the weights-v1 release. download_weights.py puts each one in backend/weights/ and checks it. backend/weights/active.json says which file each model uses.

2. App

In a second terminal, from the nextrun folder:

npm ci
npx expo start --lan

Scan the QR code with the iPhone camera (or in Expo Go on Android). The app talks to the backend on the same computer it loaded from, at port 8000, so there is nothing to configure. Set EXPO_PUBLIC_API_URL to use a backend somewhere else.

Phone and laptop must be able to reach each other. Many campus and office Wi-Fi networks block this. A phone hotspot works every time: connect the laptop to it, restart expo start --lan, and scan the new QR code.

To run it in a browser instead, use npx expo start --web. The browser version records with the webcam and uploads the clip when you stop.

3. Demo it

  1. Open Camera → Live, prop the phone up (ideally on a tripod) so the whole half-court and the hoop are in view.
  2. Tap the red button and play. Players, the ball and the hoop are tracked on screen, and every made shot is counted.
  3. Tap again to stop. The session is saved and the full analysis opens on the Upload tab.

Tips: a steady camera, good light, and the hoop in the picture make the biggest difference.

Project structure

App.tsx                  app shell, navigation, deep links
src/screens/             Home, Camera, History, Community, Profile, Settings, Onboarding
src/live/                live camera, upload, results dashboard, teams, models; API client (api.ts)
src/components/          shared UI (ui.tsx), player cards, photo editing
src/state/               app data, persistence, progression and mastery rules
src/theme/               colors, typography, bundled artwork
assets/                  fonts, icons, artwork, audio
backend/
  src/nextrun_cv/        detection, tracking, court mapping, events, stats, FastAPI app (api.py)
  tests/                 pytest suite (tests/test_live.py covers the live trackers)
  eval/                  model accuracy results shown in the Models tab
  weights/               model configs (the weights: scripts/download_weights.py)
  scripts/               download_weights.py
tests/                   app regression tests

Checks

npm run check                                              # TypeScript + app tests
cd backend && PYTHONPATH=src ../.venv/bin/python -m pytest # backend tests

Tech stack

  • App: Expo SDK 58, React Native 0.88, React 19, TypeScript, NativeWind, expo-camera, react-native-svg, Skia, Reanimated.
  • Backend: Python, FastAPI, OpenCV, Ultralytics YOLO:
    • pose model for players;
    • a custom ball and hoop detector;
    • a court-keypoint model.
  • Tracking: BoT-SORT with person re-identification for uploads; for live mode, custom trackers in backend/src/nextrun_cv/api.py.

Known limits

  • Blurry footage: players the detector can't see at all (heavy blur, very far away, or filmed off another screen) can't be tracked. A steady phone pointed at a real court works best.
  • Simulated social features: accounts, friends, messages and clubs are local to the device. There is no multi-device server yet.
  • Not a pixel-perfect port: the UI was rebuilt natively from the original design (reference/NextRun1.0.html). Some web-only effects are still frames rather than live 3D: canvas scenes, CSS blur and glow.

About

AIM Fall 2026: NextRun — Basketball stat tracking application and community platform.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages