Real-time golf putting simulator using computer vision (YOLOv8) and physics prediction. Place a real golf ball, putt it, and watch the predicted trajectory animate on a 2D canvas dashboard.
- Place the ball in the start circle → system shows READY with a beep
- Putt the ball → system enters TRACKING mode
- Ball crosses the detection line → system predicts the trajectory using physics
- Animated result appears on the 2D canvas with speed, angle, and distance
┌─────────────────────────┐
│ PREDICTION ZONE │ ← Physics engine predicts here
│ (above yellow line) │
├─────────────────────────┤ ← Yellow midline (30% from top)
│ │
│ DETECTION ZONE │ ← YOLO tracks the ball here
│ (below yellow line) │
│ │
│ ⚪ ← START │ ← Ball placement circle (82% down)
│ │
└─────────────────────────┘
┌──────────┐ WebSocket ┌──────────┐ HTTP/WS ┌──────────┐
│ Phone │ ──────────────→ │ Server │ ←──────────→ │ Browser │
│ Camera │ MJPEG frames │ FastAPI │ Telemetry │Dashboard │
└──────────┘ └────┬─────┘ └──────────┘
│
┌────────┴────────┐
│ │
┌─────┴─────┐ ┌──────┴──────┐
│ Vision │ │ Physics │
│ Engine │ │ Engine │
│ (YOLOv8) │ │ (Kinematics)│
└───────────┘ └─────────────┘
| File | Description |
|---|---|
server.py |
FastAPI server with WebSocket, camera streaming, shot broadcasting |
vision.py |
YOLOv8 ball detection, Kalman filter tracking, state machine (IDLE→READY→TRACKING→COOLDOWN) |
physics.py |
Stimpmeter-based physics, velocity→distance prediction, deceleration model |
config.py |
Configuration constants (camera, physics, detection thresholds) |
static/app.js |
Canvas renderer, shot animation, WebSocket client, scorecard |
static/style.css |
Premium dark dashboard theme |
static/index.html |
Dashboard layout with sidebar, scorecard, shot analysis, telemetry |
static/mobile.html |
Phone camera streaming page |
- Python 3.10+
- A phone camera (or webcam)
- Both devices on the same WiFi network
git clone https://github.com/yourusername/PuttSim.git
cd PuttSim
# Create virtual environment
python -m venv venv
source venv/bin/activate # macOS/Linux
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtmkdir -p certs
openssl req -x509 -newkey rsa:2048 -keyout certs/key.pem -out certs/cert.pem \
-days 365 -nodes -subj '/CN=localhost'python server.pyOpen https://localhost:8000 in your browser (accept the self-signed certificate warning).
- Click 📱 Celular on the dashboard
- Scan the QR code with your phone
- Accept the camera permission on your phone
- The phone camera feed will appear in the dashboard
The simulator uses a Stimpmeter-based deceleration model:
Stimp Rating (ft) → Deceleration (m/s²)
────────────────────────────────────────
decel = (2 × g) / (stimp_ft × 0.3048)
Stimp 10 → decel ≈ 0.549 m/s²
Kinematics:
distance = v² / (2 × decel)time_to_stop = v / decel- Direction from Kalman filter velocity vector
IDLE ──→ READY ──→ TRACKING ──→ COOLDOWN ──→ IDLE
│ │ │ │
│ Ball in Ball hit Ball lost 3s timer
│ circle (leaves (crosses resets
│ 10 frames circle) line, 3 everything
│ + beep frames)
Edit config.py to adjust:
- Phone camera (recommended): Vertical/portrait mode, pointed down at the putting surface
- Webcam: Any USB webcam mounted above the putting area
- IP camera: Any MJPEG-compatible stream
MIT License — feel free to use, modify, and distribute.
