A high-performance, real-time hand landmark tracking and finger counting application. This project utilizes MediaPipe and OpenCV to provide a robust gesture-recognition interface, specifically engineered to handle complex lighting and hand orientations.
- Advanced Coordinate Logic: Uses Euclidean distance-based detection for the thumb to ensure 100% accuracy.
- Optimized for Windows: Specifically configured to bypass camera privacy blocks using the
CAP_DSHOWbackend. - Real-time Performance: High-speed landmark tracking with 21 localized points.
Building this project involved solving several deep-level system and library conflicts.This project wasn't just about the code; it was about engineering around real-world environment hurdles, Below are the key engineering challenges I overcame:
- The Mistake: Running the script in a global Python environment led to an
AttributeError: module 'mediapipe' has no attribute 'solutions'. - The Debugging Skill: I diagnosed a version mismatch in the MediaPipe library. I implemented a Virtual Environment (venv) and pinned the project to MediaPipe 0.10.21 and NumPy 1.26.4, ensuring a stable and reproducible build.
- The Mistake: Encountered a "gray screen" where the camera would initialize but fail to provide a feed due to Windows 11 privacy layers.
- The Debugging Skill: I researched video capture backends and successfully implemented
cv2.CAP_DSHOW(DirectShow). This allowed the software to communicate directly with the hardware, bypassing the OS-level gray-screen block.
- The Mistake: A simple Y-coordinate comparison caused a "+1 offset" error, as the thumb moves on a different axis than the fingers.
- The Debugging Skill: I optimized the counting algorithm by moving from simple coordinate checks to Euclidean Distance calculations. By measuring the distance between the thumb tip (Landmark 4) and the pinky base (Landmark 17), the counter became 100% accurate for both left and right hands.
-
Math Logic:
$d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}$
- The Mistake: Staged over 10,000 files from the
venvfolder, causing repository bloat and massive terminal warnings. - The Debugging Skill: I mastered
.gitignoreimplementation. I learned how to reset the Git index usinggit rm -r --cached .and successfully reduced the repository size from 200MB+ to under 1MB.
- The Mistake: PowerShell blocked the virtual environment activation script (
PSSecurityException). - The Debugging Skill: I learned to safely manage Execution Policies using
Set-ExecutionPolicy -Scope Process, allowing the environment to run without compromising overall system security.
- Clone the Project:
git clone [https://github.com/your-username/AI-Hand-Gesture-Counter.git](https://github.com/your-username/AI-Hand-Gesture-Counter.git) cd AI-Hand-Gesture-Counter