This repository contains a Python script for hand tracking using MediaPipe and OpenCV. It utilizes the MediaPipe library to detect and track hands in a live webcam feed, drawing landmarks and connections on the detected hands.
- Python 3.x π
- OpenCV (
cv2
) π· - MediaPipe (
mediapipe
) π₯
To install the required libraries, run the following command:
pip install opencv-python mediapipe
-
Clone this repository or download the
HandTracking.py
script. -
Run the script using the following command:
python HandTracking.py
-
Once the script is running, it will open your webcam feed and start detecting and tracking your hands.
-
You'll see landmarks and connections drawn on your hands in real-time.
-
Press the 'Esc' key to exit the program.
- Detects and tracks multiple hands in a webcam feed.
- Draws landmarks and connections on the detected hands for visualization.
- Calculates and displays the frame rate (FPS) of the webcam feed.
- HandGestureImageHolder.py script showcases an example of how to display a custom image on the screen and it gives the illusion that you are holding an image with just your three fingers (thumb,index and middle). The picture will move along the screen as long as you are maintaining this specific (Italian) gesture
You can import the HandTrackingModule.py script and customize the behavior of the hand detector by modifying the parameters in the handDetector class constructor of the script. Here are some parameters you can adjust:
mode
: Set toTrue
if using static images (default isFalse
for webcam feed).maxHands
: Maximum number of hands to detect (default is2
).detectionCon
: Minimum confidence threshold for hand detection (default is0.5
).trackCon
: Minimum confidence threshold for hand tracking (default is0.5
).
You can also modify the drawing specifications (e.g., colors, thickness) by editing the findHands()
and findPosition()
methods in the handDetector
class.
This script utilizes the following libraries:
- OpenCV - Open Source Computer Vision Library
- MediaPipe - A cross-platform framework for building multimodal applied ML pipelines
Special thanks to Murtaza's Workshop - Robotics and AI for their valuable tutorials and resources in the field of Robotics and AI.
This project is licensed under the MIT License - see the LICENSE file for details.