This project enables immersive and intuitive game control using hand gestures detected through a webcam. It leverages the power of OpenCV and Mediapipe for real-time hand tracking and gesture recognition, translating hand movements into corresponding in-game actions.
- Real-time Hand Tracking: Accurately detects and tracks hand movements in real-time using OpenCV and Mediapipe.
- Intuitive Gesture Mapping: Maps specific hand gestures to predefined game commands (left, right, up, down).
- Customizable Control Region: The active control area is visually defined within the camera feed, allowing for personalized adjustments.
- Cooldown Mechanism: Implements a cooldown timer to prevent unintended repeated actions from a single gesture.
- Hand Detection & Tracking: The
hand_tracking.pymodule uses Mediapipe's hand tracking model to identify and track the user's hand within the camera frame. - Landmark Extraction: Key landmark points on the detected hand are extracted, providing coordinates for gesture analysis.
- Gesture Recognition: The
game_control.pymodule analyzes the relative positions of specific landmarks to recognize predefined gestures. - Command Execution: Recognized gestures trigger corresponding keyboard inputs, effectively controlling the game.
- Python 3.9 and above
- OpenCV (
pip install opencv-python) - Mediapipe (
pip install mediapipe) - Keyboard (
pip install keyboard)
- Clone the repository:
git clone https://github.com/your-username/your-repo-name.git - Navigate to the project directory:
cd your-repo-name - Install the required libraries:
pip install -r requirements.txt
- Ensure your webcam is connected and accessible.
- Run the main script:
python game_control.py - The application window will open, displaying the camera feed with the active control area.
- Position your hand within the control area and perform gestures to control the game.
- Gesture Mapping: You can modify the gesture-to-command mapping in the
game_control.pyscript to suit your preferences. - Control Area: Adjust the coordinates defining the active control region in the
game_control.pyscript to fine-tune the interactive space. - Cooldown Duration: Modify the
cooldown_durationvariable ingame_control.pyto adjust the delay between consecutive actions.