How godkode69/open-gestures works
1. Composition root: main.py
- main.py is the runtime entry point and the place where the whole system is wired together.
- It opens the webcam, configures MediaPipe’s GestureRecognizer, runs the frame loop, receives recognition results, calls the router, and draws the on-screen overlay/window.
2. Camera + inference pipeline
- The system reads frames from OpenCV (cv2.VideoCapture), converts them for MediaPipe, and sends them to the recognizer in LIVE_STREAM mode.
- MediaPipe runs recognition asynchronously and returns results through a callback, so the main loop and the ML callback are separated by a thread-safe handoff.
3. Thread boundary / result handoff
- Recognition results arrive on a MediaPipe callback thread.
- A lock in the core layer is used to safely transfer the latest GestureRecognizerResult to the main loop, which then consumes the most recent result when deciding what action to fire.
4. Gesture definition layer: gestures/
- Gesture logic is split into many small modules under gestures/static/ and gestures/motion/.
- Static gestures represent single-frame hand poses; motion gestures represent temporal or directional movement.
- Files ending in _2 are treated as two-hand gestures and are prioritized above _1 single-hand gestures.
5. Dynamic gesture discovery
- Gestures are not hard-coded into the router.
- They are discovered and imported dynamically at runtime, which makes the gesture catalog extensible without editing the main pipeline.
- Each gesture module exposes a name and a matches(result) predicate so the router can test it against the latest MediaPipe output.
6. Routing and priority: core/router.py
- The router is the decision layer that maps recognized gestures to actions.
- It evaluates gesture modules in priority order, so more specific or two-hand gestures can preempt simpler ones.
- This is the main control boundary between perception and actuation.
7. Temporal state: core/cooldown.py and core/swipe_tracker.py
- Cooldown prevents repeated firing from a held pose or slowly changing gesture by gating each gesture name for a period of time.
- swipe_tracker.py likely maintains frame-to-frame state for motion gestures, allowing swipe-style recognition to span multiple frames instead of relying on a single snapshot.
8. Action layer: actions/
- Actions are modular and grouped by concern and platform:
- actions/media/ for playback and volume control
- actions/util/ for brightness, screenshots, zoom, window management
- actions/app/ for launching apps or files
- actions/linux/, actions/mac/, actions/win/ for OS-specific launch/search behavior
- These modules are the system’s side-effect boundary: they translate a recognized gesture into a real desktop action.
9. OS-specific boundaries
- The repo is cross-platform at the architecture level, but some actions are explicitly platform-bound.
- For example, there are Linux terminal and macOS Spotlight modules, plus Windows Start Menu support.
- This means the gesture pipeline is shared, while the final action execution path diverges by operating system.
10. Configuration and user bindings: core/config.py and data/config.json
- data/config.json is the persistent configuration store.
- It likely holds gesture-to-action assignments, defaults, and user-customized bindings, since the README mentions switching actions and resetting them to default.
- core/config.py is the code boundary that loads, interprets, and updates that persisted state.
11. Model assets: models/
- The ML assets are shipped separately from code:
- gesture_recognizer.task for gesture classification
- hand_landmarker.task for landmark detection
- These are the runtime ML dependencies used by MediaPipe Tasks, and they define the inference capabilities of the app.
12. Runtime output
- The application displays an OpenCV window with gesture labels and the last fired action, plus preview/overlay feedback.
- That UI is not a separate frontend; it is part of the main camera loop and serves as the operator feedback layer for the gesture control system.
13. Overall data flow
- Webcam frame → OpenCV preprocessing → MediaPipe asynchronous recognition → thread-safe latest result → gesture router → cooldown check → action module execution → OS-level effect.
- The key architectural boundaries are perception, gesture classification, routing/state, and platform action execution.
14. Key architectural style
- This repo is a modular desktop control system built around plug-in-like gesture and action modules.
- The central design goal is extensibility: new gestures or actions can be added by dropping in a module, while the main loop and router remain largely unchanged.
Main entry points: system.py System Actions · main.py main.py · router.py Router · static Static Gestures
Components 17
Runtime
Entry point and frame loop
- main.py · Wires camera, recognizer, router, and overlay loop
main.py
Core
Routing, cooldown, config, and gesture state
- Config · Loads and persists gesture/action bindings
core/config.py - Router · Matches recognized gestures to actions by priority
core/router.py - Cooldown · Prevents repeated firing of the same gesture
core/cooldown.py - Swipe Tracker · Maintains frame-to-frame state for swipe gestures
core/swipe_tracker.py
Gestures
Static and motion gesture modules
- Static Gestures · Single-frame hand pose recognizers
gestures/static - Motion Gestures · Temporal and directional gesture recognizers
gestures/motion
Actions
User-facing and OS-specific side effects
- Action Base · Shared action abstractions and execution contracts
actions/base.py - System Actions · Top-level system action dispatch and integration
actions/system.py - Media · Playback and volume control actions
actions/media - Utilities · Brightness, screenshots, zoom, and windows
actions/util - Apps · Launches apps, files, and browsers
actions/app - Linux · Linux-specific terminal or launch behavior
actions/linux - macOS · macOS-specific search and launch behavior
actions/mac - Windows · Windows Start Menu integration
actions/win
Assets
ML models shipped with the app
- Gesture Model · MediaPipe gesture recognizer task model
models/gesture_recognizer.task - Hand Model · MediaPipe hand landmark detector model
models/hand_landmarker.task
Connections 18
- main.py → Config: load bindings · Reads persistent gesture/action configuration
- main.py → Router: route results · Sends latest recognition result into decision layer
- main.py → Gesture Model: use model · Runs gesture recognition with the shipped task model
- main.py → Hand Model: use model · Uses hand landmarks for inference support
- main.py → Static Gestures: discover · Loads static gesture modules dynamically
- main.py → Motion Gestures: discover · Loads motion gesture modules dynamically
- Router → Cooldown: gate repeat · Applies cooldown before firing an action
- Router → Swipe Tracker: track motion · Consumes frame-to-frame swipe state
- Router → Static Gestures: match · Evaluates static gesture predicates
- Router → Motion Gestures: match · Evaluates motion gesture predicates
- Router → System Actions: dispatch · Triggers the selected action path
- System Actions → Action Base: implement · Builds on shared action abstractions
- System Actions → Media: media · Handles playback and volume actions
- System Actions → Utilities: utility · Handles desktop utility actions
- System Actions → Apps: app launch · Handles app, file, and browser launching
- System Actions → Linux: linux · Delegates Linux-specific actions
- System Actions → macOS: macOS · Delegates macOS-specific actions
- System Actions → Windows: windows · Delegates Windows-specific actions