This project allows users to control keyboard actions using color-based gestures captured through a webcam. The system detects specific colors in the video feed and triggers corresponding key presses.
Before you begin, ensure you have met the following requirements:
- Python 3.x installed on your system.
pip
for managing Python packages.
##Installation
-
Clone the repository:
git clone https://github.com/yourusername/gesture-control.git cd gesture-control
-
Create and activate a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
Install the necessary Python packages using
pip
:pip install opencv-python imutils numpy pynput
opencv-python
: For capturing and processing video feed.imutils
: For easier OpenCV usage.numpy
: For numerical operations.pynput
: For controlling the keyboard programmatically.
-
Run the code:
Ensure your webcam is connected and accessible. Run the
tutorial.py
file to start the gesture recognition system:python tutorial.py
-
Control the system:
The system will display a window showing the webcam feed. It recognizes color-based gestures:
- LEFT: Move the object to the left side of the screen to trigger the 'A' key.
- RIGHT: Move the object to the right side of the screen to trigger the 'D' key.
- NITRO: Move the object to the bottom center to trigger the 'Space' key.
-
Exit the program:
Press the
q
key to quit the program.
To modify the color range detected by the system, you can adjust the colourLower
and colourUpper
variables in the script. These define the HSV color ranges for the object being tracked.
Example:
colourLower = np.array([94, 138, 115])
colourUpper = np.array([180, 255, 255])
Change the values to suit your desired color range.
tutorial.py
: Main script that runs the gesture detection and keyboard control.color.py
: Utility file for color detection (ensure this is correctly referenced in the main script).
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
You can copy this code and save it as `README.md` in the root directory of your project. This will automatically be recognized by GitHub when you push your project repository online.