- This project demonstrates a real-time hand gesture recognition system using Python, OpenCV, and Gemini AI by Google.
- The system allows users to solve math problems by drawing them in the air.
- The repository contains all the code and resources needed to implement this project.
- Real-time hand detection and tracking using OpenCV and cvzone.
- Recognition of specific hand gestures to perform actions like drawing, clearing canvas, and requesting math problem solutions.
- Integration with Gemini AI for solving math problems based on gestures.
- Python 3.10.12
- cvzone
pip install cvzone
- OpenCV
pip install opencv-python
- Gemini AI
pip install google-generativeai
- Python packages
- numpy
pip install numpy
- pillow
pip install pillow
- numpy
- C++ compiler - install Visual Studio
-
Clone the repository:
git clone https://github.com/LasithaAmarasinghe/Hand-Gesture-Math-Solver.git cd Hand-Gesture-Math-Solver
-
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:
pip install -r requirements.txt
-
Get a Gemini API key
You can get an API key from here
-
Replace API key in the code with the obtained API key
-
Execute the main script
python math_solver.py
-
Interact with the Application
- Live Feed
- The application will display the live feed from your webcam.
- Perform Hand Gestures
- Draw: Use one finger to draw on the canvas.
- Clear: Use one finger to clear the canvas.
- Solve Math Problem: Use all fingers except the thumb to submit a math problem for solving.
- Live Feed
-
getHandInfo(img)
- Purpose: Detects and tracks the user's hand in each frame of the webcam feed.
- Implementation: Uses the HandTrackingModule to identify and monitor hand movements.
-
draw(info, prev_pos, canvas)
- Purpose: Draws on the canvas based on the detected hand gestures.
- Parameters:
info
: Information about the detected hand gestures.prev_pos
: Previous position of the drawing.canvas
: Canvas to draw on.
-
sendToAI(model, canvas, fingers)
- Purpose: Sends the drawn content to Google's Generative AI for math problem solving based on recognized gestures.
- Parameters:
model
: Instance of the Generative AI model.canvas
: Canvas containing the drawn content.fingers
: Array indicating the state of fingers (e.g., for gesture recognition).

Left-Right Hand Detection


Hand Gesture Detection


Math Expression Detection & Canvas


- This project is licensed under the MIT License. See the LICENSE file for details.