A real-time fingers counter using Python, OpenCV, and Mediapipe.
This project is a real-time fingers counter that uses a webcam to detect a human hand and count the number of fingers being held up. It leverages the power of computer vision libraries to perform hand landmark detection and display the count on the screen.
- Real-time video capture from a webcam.
- Accurate hand detection using Google's Mediapipe library.
- Visualization of hand landmarks and connections.
- Logic to count the number of extended fingers.
- Display of the finger count as an on-screen overlay.
- Python 3.6+
- A webcam
- Clone the repository:
git clone https://github.com/aliallouf/Fingers-Counter-Python.gitcd Fingers-Counter-Python - Install the required Python packages:
pip install opencv-python mediapipe
To run the application, simply execute the main Python script:
python main.py
Press q to exit the application.
cam = cv2.VideoCapture(0): Initializes the webcam.hands = mp_hands.Hands(...): Sets up the Mediapipe hand detection model.results = hands.process(frame_rgb): Processes each frame to find hand landmarks.- Finger Counting Logic: The core logic compares the Y-coordinates of the fingertip landmarks with their corresponding knuckle landmarks to determine if a finger is extended.
cv2.putText(...): Renders the finger count as text on the output frame.