How itanmayi/open-gestures works
1. This repository is a webcam-driven gesture control runtime. The top-level flow is: capture video frames, run MediaPipe gesture recognition asynchronously, match the latest recognition result against a set of gesture rules, then execute a mapped system action.
2. main.py is the orchestrator. It owns the camera loop, configures the MediaPipe recognizer, feeds frames into recognize_async(), receives results through a callback, and passes the most recent result to the router. It also draws the on-screen overlay and opens the OpenCV display window.
3. There is an explicit threading boundary between MediaPipe and the main loop. MediaPipe runs recognition in live-stream mode on an internal thread, and the callback writes the latest GestureRecognizerResult into a shared slot guarded by a threading.Lock. The main loop consumes that slot on each frame, which keeps rendering and input capture responsive.
4. core/ contains the central control logic:
- core/router.py decides which gesture module matches the current result and which action should fire.
- core/cooldown.py prevents repeated firing from a held pose or slow-changing gesture.
- core/config.py appears to centralize runtime configuration and/or loading of stored bindings from data/config.json.
5. The gesture layer is modular and data-driven. gestures/static/ contains one Python module per gesture pose, with files named like thumb_up_1.py and thumb_up_2.py. The naming suggests _2 variants represent two-hand gestures and are treated with higher priority than _1 single-hand variants, matching the README’s two-hand-first rule.
6. Each gesture module is a small rule object rather than a standalone feature. The contract described in the README is: export a unique GESTURE_NAME and a matches(result) function. That means gesture detection is separated from execution; modules only decide whether the current MediaPipe result satisfies their pose or temporal pattern.
7. The action layer is also modular, with a clear boundary between “what was recognized” and “what should happen.” actions/base.py and actions/system.py suggest a shared action abstraction, while feature-specific actions live under subpackages:
- actions/media/ for playback and volume control
- actions/util/ for brightness, screenshots, zoom, and window management
- actions/app/ for launching apps, browser, files
- actions/linux/, actions/mac/, and actions/win/ for OS-specific commands
8. The OS-specific folders are important architectural boundaries. They indicate that the repo aims to support Linux, macOS, and Windows with the same gesture-to-action pipeline, while the final execution step is delegated to platform-tailored action modules. This keeps recognition portable and pushes OS dependency to the edges.
9. data/config.json is the persistence layer for user-facing bindings and/or preferences. Based on the README, the UI lets users switch actions and reset defaults, so this file likely stores the current gesture-to-action mapping that the router reads at startup.
10. models/ holds the MediaPipe model assets used at runtime. gesture_recognizer.task is the primary recognition model referenced in the README, and hand_landmarker.task is also present as a model artifact. These files are external ML dependencies rather than application code, so they form the ML inference boundary of the system.
11. The repository also includes a .wip/swipe_tracker.py, which looks like an experimental or unfinished gesture-tracking component. It is separate from the main runtime path and should be treated as non-production or in-progress logic.
12. For an architecture diagram, the key runtime path is: webcam/OpenCV input → MediaPipe recognizer callback → thread-safe latest-result buffer → gesture router with cooldown checks → action modules → OS/system effects, with config and bindings loaded from data/config.json and overlay/UI rendered back through OpenCV.
Main entry points: system.py system.py · static Static rules · main.py main.py · router.py router.py
Components 25
Runtime
Live webcam loop and inference thread boundary
- main.py · Owns camera loop, async recognition, result buffering, routing, and overlay rendering
main.py - Camera loop · Captures webcam frames and presents the UI window
main.py - MediaPipe async · Runs live-stream gesture recognition on MediaPipe's internal thread
main.py - Latest result · Thread-safe handoff slot guarded by a lock for the newest recognizer result
main.py - Overlay UI · Draws on-screen feedback over the camera feed
main.py
Core
Configuration, routing, and cooldown control
- router.py · Matches recognized gestures to configured actions
core/router.py - cooldown.py · Prevents repeated firing from held or slowly changing gestures
core/cooldown.py - config.py · Loads bindings and runtime settings, including data/config.json
core/config.py
Gestures
Gesture rule modules and priority variants
- Static rules · Data-driven gesture pose modules under gestures/static/
gestures/static - thumb_up_1 · Representative static gesture module
gestures/static/thumb_up_1.py - thumb_up_2 · Higher-priority two-hand variant of the thumb-up gesture
gestures/static/thumb_up_2.py - victory_1 · Representative static gesture module
gestures/static/victory_1.py - victory_2 · Higher-priority two-hand variant of the victory gesture
gestures/static/victory_2.py
Actions
Action abstractions and platform-specific effects
- base.py · Shared action abstraction used by the execution layer
actions/base.py - system.py · System-facing action entrypoints and shared execution helpers
actions/system.py - Media actions · Play, pause, mute, and volume-related actions
actions/media - Utility actions · Brightness, screenshots, zoom, and window management
actions/util - App actions · Launches browser, files, and custom apps
actions/app - Linux · Linux-specific command execution
actions/linux - macOS · macOS-specific command execution
actions/mac - Windows · Windows-specific command execution
actions/win
Assets
Runtime data and model artifacts
- config.json · Persisted gesture-to-action bindings and preferences
data/config.json - gesture_recognizer.task · Primary MediaPipe gesture recognition model
models/gesture_recognizer.task - hand_landmarker.task · Hand landmark model used by the inference stack
models/hand_landmarker.task
Experimental
Work-in-progress gesture tracking
- swipe_tracker.py · Experimental or unfinished gesture-tracking logic
.wip/swipe_tracker.py
Connections 25
- main.py → Camera loop: captures frames · The main runtime owns webcam input and the display loop
- main.py → MediaPipe async: feeds frames · Frames are submitted to MediaPipe in live-stream mode
- MediaPipe async → Latest result: callback writes · The recognizer callback stores the newest result under a lock
- Camera loop → Latest result: reads latest · The render loop consumes the most recent recognition result each frame
- main.py → Overlay UI: renders · Camera output is decorated with recognition feedback
- Latest result → router.py: dispatches · Latest recognition result is evaluated by the router
- config.py → router.py: loads bindings · Routing decisions are driven by configured gesture-action mappings
- config.json → config.py: persists · Stored preferences and bindings are loaded at startup
- router.py → cooldown.py: checks repeats · Cooldown prevents retriggering from held poses
- router.py → Static rules: matches rules · Router evaluates the active gesture modules
- Static rules → thumb_up_1: contains · Representative single-hand static rule
- Static rules → thumb_up_2: contains · Representative two-hand static rule
- Static rules → victory_1: contains · Representative single-hand static rule
- Static rules → victory_2: contains · Representative two-hand static rule
- router.py → base.py: selects · Matched gestures are resolved to a concrete action abstraction
- base.py → system.py: executes via · Common action contract delegates to system-facing execution
- system.py → Media actions: routes · Media-control behavior is implemented in a dedicated module set
- system.py → Utility actions: routes · Desktop utility behavior is implemented in a dedicated module set
- system.py → App actions: routes · Application-launch behavior is implemented in a dedicated module set
- system.py → Linux: adapts · Linux-specific commands live at the platform edge
- system.py → macOS: adapts · macOS-specific commands live at the platform edge
- system.py → Windows: adapts · Windows-specific commands live at the platform edge
- main.py → gesture_recognizer.task: uses model · The runtime loads the gesture recognizer task asset
- main.py → hand_landmarker.task: uses model · The runtime also depends on the hand landmark model asset
- swipe_tracker.py → Static rules: experimental path · Work-in-progress tracking is separate from the main runtime flow