Real-time physical dice detection for D&D with Foundry VTT integration.
- Live Camera Detection: Detect dice from your webcam in real-time
- Multiple Dice Support: D4, D6, D8, D10, D12, D20, D100
- Multi-Stage Rolling: Roll formulas requiring more dice than you own across multiple throws
- Modifier Presets: Configure attack rolls, damage, saving throws with bonuses
- Confidence System: Manual correction for uncertain detections
- Foundry VTT Integration: Send roll results via browser extension
- Local API: FastAPI-based REST and WebSocket API
This project uses uv for dependency management.
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and enter the project
cd dice_detector
# Sync dependencies
uv syncuv run uvicorn dice_detector.api:app --reloadThe API will be available at:
- HTTP:
http://localhost:8765 - WebSocket:
ws://localhost:8765/ws - API Docs:
http://localhost:8765/docs
uv run pytest --cov# Linting
uv run ruff check src tests
# Type checking
uv run mypy src
# Format code
uv run ruff format src testsdice_detector/
├── src/dice_detector/
│ ├── api/ # FastAPI REST and WebSocket API
│ ├── models/ # Pydantic data models
│ ├── camera/ # Webcam capture
│ ├── vision/ # Dice detection and recognition
│ ├── roll_engine/ # Roll calculation and presets
│ ├── foundry/ # Foundry VTT integration
│ ├── ui/ # GUI application (future)
│ ├── training/ # Dataset and model training
│ └── config/ # Settings management
├── extension/ # Browser extension for Foundry
├── tests/ # Test suite
└── data/ # Presets and samples
The app supports rolling formulas that require more dice than you physically own:
Formula: 2d20 + 2d4
Physical dice: 1x D20, 1x D4
Stage 1: Roll D20 (13) and D4 (2)
Stage 2: Roll D20 (18) and D4 (4)
Result: 13 + 18 + 2 + 4 = 37
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/status |
GET | Current app status |
/config |
GET/POST | Configuration |
/presets |
GET/POST | Modifier presets |
/roll/start |
POST | Start a roll session |
/roll/current |
GET | Get current session |
/roll/accept |
POST | Accept detected dice |
/roll/confirm |
POST | Confirm and complete roll |
/roll/cancel |
POST | Cancel current session |
/roll/manual |
POST | Submit manual roll |
/foundry/payload/latest |
GET | Get latest Foundry payload |
/ws |
WebSocket | Real-time updates |
The browser extension connects the local app to Foundry VTT:
- Load the extension from
extension/in Chrome/Firefox developer mode - Start the dice detector API server
- Open Foundry VTT in your browser
- Use the extension popup to send rolls to Foundry
Edit config/settings.yaml to configure:
- Camera source
- Detection area/zone
- Confidence thresholds
- Auto-post settings
- Foundry connection details
- Install the companion Foundry module (see
foundry_module/) - Enable WebSocket connection in Foundry settings
- Configure connection in dice detector settings
Huge shoutout to dianaavlis2002 on Sketchfab/Artstation for the amazing RPG dice set used in this project's Blender scenes for synthetic data generation!
MIT License