This project allows users to recognize handwritten digits using a deep learning model (CNN) trained on the MNIST dataset.
Users can either:
βοΈ Upload an image of a digit
βοΈ Draw on a writing pad and get instant predictions
β
Image Upload β Choose an image of a digit and get a prediction
β
Interactive Writing Pad β Draw a digit using a mouse
β
Clear Canvas (Press 'C') β Erase and redraw without restarting
β
Predict Digit (Press 'P') β Get the result instantly
β
Quit (Press 'Q') β Exit the writing pad
-
Clone the repository:
git clone https://github.com/your-username/handwritten-digit-recognition.git cd handwritten-digit-recognition
-
Install dependencies:
pip install opencv-python numpy tensorflow tkinter
-
Download the trained model:
- Place the pre-trained handwriting_model.h5 inside the
models/
directory.
- Place the pre-trained handwriting_model.h5 inside the
Run the program using:
python main.py
Youβll see a menu asking you to:
1οΈβ£ Upload an image
2οΈβ£ Draw on a writing pad
For Image Upload:
- Select an image (
.png, .jpg, .jpeg
) containing a digit. - The system will process and display the predicted digit.
For Writing Pad:
- Draw a digit using your mouse.
- Press 'C' to clear and redraw.
- Press 'P' to predict the drawn digit.
- Press 'Q' to exit.
π handwritten-digit-recognition
βββ π models
β βββ handwriting_model.h5 # Pre-trained CNN model
βββ digit_recognition.py # Main program to Train & Run the Model
βββ realtime_digit_recognition.py # Program to Acces the Local File & Writting Pad
βββ README.md # Project documentation
- Image Processing: Converts images to grayscale, resizes (28x28), normalizes, and inverts colors.
- CNN Model Prediction: Trained on MNIST dataset, predicts digit with softmax classification.
- OpenCV GUI: Provides an interactive writing pad for drawing digits.
Want to improve this project? Feel free to fork and submit a pull request!
This project is open-source and free to use! π