Draw math. Get answers. Instantly.
Write any math expression by hand — just like on paper — and this AI reads it, understands it, and gives you the answer in real time.
No keyboard. No typing. Just draw.
You draw on screen
↓
OpenCV detects each symbol
↓
CNN model reads what you wrote (99.63% accuracy)
↓
SymPy solves the expression
↓
Answer appears instantly
Supports:
- ➕ Addition
2 + 3 = 5 - ➖ Subtraction
9 - 4 = 5 - ✖️ Multiplication
6 * 7 = 42 - ➗ Division
10 / 2 = 5 - 🔢 Multi-digit numbers
12 + 34 = 46 - 📐 Equations
2x + 3 = 7 → x = 2
git clone https://github.com/yourusername/handwritten-math-solver
cd handwritten-math-solverpython -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpython train_model.pypython main.py| Key | Action |
|---|---|
| Draw | Use mouse to write on the canvas |
| S | Solve the expression |
| C | Clear the canvas |
| Q | Quit |
The model is a Convolutional Neural Network (CNN) trained from scratch on:
- 60,000 handwritten digit images from the MNIST dataset
- 24,000 synthetic operator images (custom generated for +, -, ×, ÷)
The architecture uses multiple Conv2D layers with BatchNormalization and Dropout for regularization — achieving 99.63% test accuracy.
handwritten-math-solver/
├── model/
│ ├── math_model.keras ← Trained CNN model
│ └── classes.npy ← Symbol class labels
├── main.py ← Live camera + detection app
├── train_model.py ← CNN training script
├── solver.py ← Math expression evaluator
└── requirements.txt
tensorflow
opencv-python
numpy
sympy
cvzone
matplotlib
scikit-learn
| Tool | Purpose |
|---|---|
| TensorFlow / Keras | CNN model training & inference |
| OpenCV | Real-time drawing canvas & contour detection |
| SymPy | Mathematical expression solving |
| NumPy | Data processing & array operations |
Saeed Fahim BTech — Artificial Intelligence & Machine Learning Chandigarh University
Built as part of an AI/ML portfolio to demonstrate real-world deep learning applications.
