motiondetector is a Windows-focused Python application that detects on-screen motion inside a user-selected region.
It combines:
- a transparent Qt overlay for region and tile selection,
- a background capture/analysis loop,
- a local FastAPI server for JSON and dashboard access,
- optional audio-aware state classification,
- optional synthetic test-data training mode,
- optional clip recording driven by detector state.
- Create and activate a virtual environment.
- Install dependencies:
pip install -r requirements.lock.txt
- Run:
python main.py
- Open dashboard:
http://127.0.0.1:8735
- Main thread: Qt selector overlay and user interaction.
- Monitor thread: screen capture, motion analysis, state assignment, optional recording.
- Server thread: FastAPI + static dashboard assets.
- Shared state boundary:
StatusStore(thread-safe latest payload, history, tile mask, UI settings, quit flag).
- Always-on-top transparent region selector.
- Configurable grid (
rows x cols) aligned with analyzer tile layout. - Click-to-toggle disabled tiles; disabled tiles are masked as
nullin API payloads. - Runtime synchronization of grid, tile labels, overlay state text, and region through
/uiAPIs.
- Capture backend:
MSS. - Frame differencing + grayscale-based scoring.
- Per-frame instant metrics and smoothed metrics.
- Per-tile values published in row-major order.
- Configurable thresholds for
NO_MOTION,LOW_ACTIVITY,MOTION. - No-motion grace voting to reduce state flapping.
- Optional analysis inset (
analysis_inset_px) to ignore noisy borders.
- Optional audio signal integration.
- Supports WASAPI session metering and loopback capture backends.
- Emits combined motion/audio state families, including audio-hardware unavailable fallbacks.
- JSON endpoints for latest status, history, tile mask, UI settings, and shutdown.
- Lightweight dashboard served from
server/assets.
- Start with
--testdata,--testdata-fast, or--testdata-slow. - Generates deterministic scenes and logs detector behavior to
./testdata_logs. - Useful for threshold tuning and regression checking without live screen dependence.
- Trigger clips from selected detector states.
- Cooldown and stop-grace controls help prevent noisy clip churn.
python main.pypython main.py --testdatapython main.py --testdata-fastpython main.py --testdata-slowpython main.py --testdata --testdata-seed 1337
Audio utility:
python tools/audio_device_selector.pypython tools/audio_device_selector.py --select 0
Primary configuration file: config/config.json
Key groups:
server.*host/port.capture.*backend/fps.motion.*thresholds, smoothing, normalization, grid, history, inset, grace voting.recording.*recorder controls.audio.*audio backend and thresholds.ui.*initial region and overlay display options.
Base URL (default): http://127.0.0.1:8735
GET /dashboard.GET /statuslatest payload.GET /historyrolling payload history.GET /tilesget disabled tile indices.PUT /tilesset disabled tile indices.GET /uiget UI runtime settings.POST /ui/tile-numbersset tile-label visibility.POST /ui/gridset runtime grid size.POST /ui/state-overlayset state text overlay visibility.POST /ui/regionset runtime region.GET /ui/settingscompatibility alias of/ui.POST /quitgraceful shutdown request.
- Architecture:
docs/architecture.md - Developer guide:
docs/developer-guide.md - User stories:
docs/user-stories.md - Backlog:
docs/backlog.md
- Intended platform: Windows.
- Python 3.x.
- Pinned dependencies in
requirements.lock.txt.
- Keep server bound to loopback (
127.0.0.1) for local-only safety unless you intentionally expose it. - Larger tile grids increase CPU cost and visual noise.