Real-time driver phone detection using a Roboflow model and OpenCV.
Create a .env file in this directory:
ROBOFLOW_API_KEY=your_key_here
Best for servers, background processes, or running against an RTSP camera stream.
The container always runs with --headless, so no display is needed.
Add RTSP_URL to your .env:
ROBOFLOW_API_KEY=your_key_here
RTSP_URL=rtsp://user:pass@192.168.1.100/stream
Then build and run:
docker compose up --buildIn docker-compose.yml, swap the command and uncomment devices:
command: ["--source", "0"]
devices:
- /dev/video0:/dev/video0Then:
docker compose up --buildNote: webcam passthrough requires Linux. On macOS, Docker Desktop does not expose USB/webcam devices to containers — use the native approach below instead.
Run the script directly in a virtual environment to get the cv2.imshow preview window.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtsource .venv/bin/activate
python src/detect.py --source 0Press q in the video window to quit.
source .venv/bin/activate
python src/detect.py --rtsp rtsp://user:pass@192.168.1.100/streampython src/detect.py --source 0 --headless| Flag | Default | Description |
|---|---|---|
--source |
0 |
Webcam index or path to a video file |
--rtsp |
— | RTSP URL; overrides --source |
--conf |
0.5 |
Confidence threshold (0–1) |
--headless |
off | Disable the preview window |