How wasifsohail5/virtual_mouse works
Project Type and Purpose
• This is a single-process, full-stack algorithmic application (no frontend UI beyond console/terminal) that captures webcam frames, processes them in real time to recognize gestures, and drives the OS mouse.
• Key libraries: OpenCV (capture & preprocessing), MediaPipe (landmark detection), custom gesture logic (distance checks + smoothing), PyAutoGUI (cursor control), NumPy (math).
Main Architectural Components
a. Input Subsystem
• Webcam Capture (OpenCV VideoStream)
b. Hand Landmark Detection
• MediaPipe Hands Module
• Landmark Extraction (21 keypoints per hand)
c. Gesture Recognition & Smoothing
• Distance Calculations (e.g., index-thumb pinch)
• State Machine for click, double-click, scroll modes
• Adaptive smoothing/filtering via NumPy
d. Cursor Control & OS Interaction
• Normalized hand positions to screen coordinates
• Mouse move, click, double-click, scroll via PyAutoGUI
e. Configuration & Thresholds
• Sensitivity parameters (click distance thresholds)
• Mode toggles (scroll on/off)
Architectural Patterns and Principles
• Pipeline Pattern: Sequential processing stages (capture → detect → recognize → control).
• Separation of Concerns: Each stage encapsulated in its own function/module.
• Single Responsibility: One class or function per major concept (e.g., “HandDetector,” “GestureController,” “CursorManager”).
• Extensibility Points: Insert new gesture modules or integrate voice commands by adding new pipeline stages.
Essential Elements
• Component Labels: e.g., “OpenCV VideoCapture,” “MediaPipe Hands,” “Gesture Engine,” “PyAutoGUI Driver.”
• Container Boundaries: Show that everything (except the webcam and OS mouse) lives inside a single Python process.