This project consists of two Python scripts that work together to create a machine learning-based symbol recognition application. The application generates a synthetic dataset of arrow symbols, trains a convolutional neural network (CNN) to recognize them, and provides a graphical user interface (GUI) for users to draw and predict symbols.
- Overview
- Features
- Requirements
- Installation
- Usage
- File Structure
- How It Works
- Limitations
- Contributing
- License
The application recognizes four arrow symbols: →, ↔, ←, and ↓. It uses a TensorFlow CNN model trained on a synthetic dataset of these symbols. The GUI, built with Tkinter, allows users to draw symbols on a canvas and predict them using the trained model.
- Generates a synthetic dataset of arrow symbols with variations (rotation, etc.).
- Trains a CNN model to classify the symbols with high accuracy.
- Provides a Tkinter-based GUI for drawing symbols and predicting them in real-time.
- Displays prediction confidence for each drawn symbol.
- Includes options to clear the canvas and re-draw.
- Python 3.6+
Libraries:
- tensorflow (for model training and prediction)
- numpy (for numerical operations)
- pillow (for image processing)
- matplotlib (for dataset visualization)
- scikit-learn (for dataset splitting)
- tkinter (for GUI, usually included with Python)
-
Clone or download this repository to your local machine.
-
Install the required dependencies using pip:
pip install tensorflow numpy pillow matplotlib scikit-learn
Note: Tkinter is typically included with Python. If not, install it:
- On Ubuntu/Debian:
sudo apt-get install python3-tk
- On macOS: Tkinter is usually pre-installed with Python.
- On Windows: Tkinter is included with standard Python installations.
- On Ubuntu/Debian:
-
Ensure you have a working Python environment with the above libraries.
-
Run the
symbol_recognition.py
script to generate the dataset and train the CNN model:python symbol_recognition.py
This script will:
- Create a dataset directory with synthetic images of the four symbols.
- Train the CNN model and save it as
symbol_recognition_model.h5
. - Display a plot of the generated symbols and training/validation accuracy.
- Print the test accuracy and predictions for sample images.
-
Ensure the
symbol_recognition_model.h5
file exists in the same directory as the scripts. -
Run the
test_prediction.py
script to start the GUI:python test_prediction.py
The GUI will open with a canvas and two buttons:
- Draw: Click and drag on the canvas to draw a symbol.
- Prever: Click to predict the drawn symbol and display the result with confidence.
- Limpar: Click to clear the canvas and start over.
symbol_recognition/
├── test_prediction.py # Script for the Tkinter GUI application
├── symbol_recognition_model.py # Script to generate dataset and train the model
├── symbol_recognition_model.h5 # Trained CNN model (generated after running train_model.py)
├── dataset/ # Directory for synthetic dataset (generated after running train_model.py)
│ ├── →/ # Images for right arrow
│ ├── ↔/ # Images for double arrow
│ ├── ←/ # Images for left arrow
│ └── ↓/ # Images for down arrow
└── README.md # This file
- Creates 1000 synthetic images per symbol (→, ↔, ←, ↓) using PIL.
- Applies random rotations to add variation.
- Saves images in a dataset directory.
- Loads and preprocesses the dataset (normalizes pixel values, reshapes for CNN).
- Splits data into training (80%) and testing (20%) sets.
- Builds a CNN with convolutional, pooling, and dense layers.
- Uses data augmentation (rotation, zoom, shifts) to improve robustness.
- Trains the model for 15 epochs and saves it as
symbol_recognition_model.h5
.
- Loads the trained model.
- Provides a 280x280 canvas for drawing with the mouse.
- Converts the drawn image to 28x28 (matching the training data) and predicts the symbol.
- Displays the predicted symbol and confidence in a message box.
- The model is trained on synthetic data, so it may struggle with hand-drawn symbols that differ significantly from the generated dataset.
- Only four symbols are supported (→, ↔, ←, ↓).
- The GUI drawing is basic and may not capture fine details of complex drawings.
- The model may misclassify symbols if the drawing is too noisy or ambiguous.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and test thoroughly.
- Submit a pull request with a clear description of your changes.
Suggestions for improvements:
- Add support for more symbols.
- Enhance the GUI with features like undo/redo or adjustable brush size.
- Improve the model with real hand-drawn data.
- Optimize the CNN architecture for better accuracy.

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