This project demonstrates a handwritten digit recognition system using Pygame for drawing digits and a trained Keras convolutional neural network (CNN) to recognize and classify the drawn digits.
The project consists of two main files:
main.py
: Contains the code for training the CNN model using the MNIST dataset and saving the best performing model.app.py
: Implements a Pygame interface where users can draw digits. The drawn digit is then recognized using the saved model and displayed on the interface.
Ensure you have the following dependencies installed:
- Python 3.x
- Keras
- Pygame
- NumPy
- OpenCV (cv2)
- Matplotlib
Install dependencies using pip:
pip install keras pygame numpy opencv-python matplotlib
- To train the model, navigate to the project directory in the terminal.
- Run the following command:
python main.py
- This script will load the MNIST dataset, preprocess the data, train a CNN model, and save the best performing model as
bestmodel.h5
.
- To run the application, execute the following command:
python app.py
- This will open a Pygame window where you can draw digits using the mouse.
- Release the mouse to trigger digit recognition.
- The recognized digit will be displayed on the screen.
- Press
n
to clear the drawing board.
-
main.py
:- Loads the MNIST dataset.
- Preprocesses the data and trains a CNN model.
- Saves the best performing model as
bestmodel.h5
.
-
app.py
:- Initializes a Pygame window for drawing digits.
- Recognizes drawn digits using the trained model.
- Displays the recognized digit on the interface.
The MNIST dataset used for training the model is sourced from the Keras library.
- Ensure that the required models (
bestmodel.h5
) are present in the respective directories before running the application.
This detailed README provides instructions on how to set up, train the model, and run the application, along with keyboard commands and dependencies. Adjustments can be made to this file to include more information or specific instructions tailored to your project's needs.