This project implements real-time hand gesture recognition to apply different image filters using a webcam.
The system detects six different hand gestures and applies corresponding filters to the webcam feed.
| Gesture | Effect |
|---|---|
| ✋ Open Palm | No filter (Default) |
| ✊ Fist | Grayscale |
| ✌️ Peace Sign | Sepia |
| 👍 Thumbs Up | Blur |
| ☝️ Pointing Finger | Edge Detection |
| 👌 OK Sign | Cartoon Effect |
Ensure you have Python installed (>=3.7). Then, install the required dependencies:
pip install opencv-python mediapipe numpy torch torchvision scikit-learn pickle-mixinAlternatively, install from the requirements.txt file:
pip install -r requirements.txtgesture-controlled-filters/
│— collect_data.py # Collects hand keypoints for model training
│— train_model.py # Trains a gesture classification model
│— apply_filters.py # Runs real-time gesture detection & filtering
│— gesture_data.pkl # Saved dataset of hand keypoints (generated by collect_data.py)
│— gesture_model.pth # Trained PyTorch model (generated by train_model.py)
│— requirements.txt # Required dependencies
│— README.md # Project documentation
Run this script to collect 200 frames per gesture using MediaPipe Hands:
python collect_data.py🛠 Instructions:
- Press Enter to start collecting for each gesture.
- Hold the gesture steady and slightly vary angles.
- Captures 200 samples per gesture.
- Press 'q' to quit data collection.
Once data is collected, train the MLP neural network:
python train_model.py💪 This will generate gesture_model.pth, which is the trained model.
python apply_filters.py👀 The webcam will display both the original frame and the filtered frame.
Try different gestures to see filters change in real time!
- Ensure your camera is enabled in system settings.
- Try running with
cv2.VideoCapture(1)if using an external webcam.
- Increase
min_detection_confidenceincollect_data.py:hands = mp.solutions.hands.Hands(min_detection_confidence=0.3)
- Ensure good lighting and clear background.
- Print model predictions:
print(f"Detected gesture: {gesture}")
- If misclassification occurs, collect more data and retrain the model.
- Adjust
cv2.adaptiveThreshold()incartoon():edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, blockSize=9, C=9)
Feel free to fork this repo and submit pull requests! Suggestions and improvements are always welcome.
🚀 Happy Coding! 🎬✨