This project is a shape classification system that recognizes circles, squares, and triangles using image processing techniques (not deep learning-based feature extraction). The extracted features are then classified using an Artificial Neural Network (ANN).
shape_classifier_project/
│
├── data/
│ └── geometric_shapes_dataset/
│ ├── Circle/
│ ├── Square/
│ └── Triangle/
│
├── train_model.py # Trains the ANN with image processing features
├── predict_live.py # Uses the webcam to predict shape in real time
├── shape_utils.py # Feature extraction function
├── model.pkl # Trained ANN model
├── scaler.pkl # StandardScaler for feature normalization
└── README.md # You are here
| Step | Tool / Method |
|---|---|
| Feature Extraction | OpenCV (area, perimeter, circularity from contours) |
| Classification | MLPClassifier from scikit-learn (ANN) |
| Input Dataset | Custom-labeled shape images (one folder per class) |
| Live Prediction | Webcam input processed in real time with OpenCV |
Make sure your dataset is placed under data/geometric_shapes_dataset/ with three folders:
Circle/Square/Triangle/
Then run:
python train_model.pyAfter the model is trained and saved, run:
python predict_live.pyUse a plain black background and draw simple geometric shapes in white for best results.
The system extracts the following features from each contour:
- Area
- Perimeter
- Circularity
[ \text{Circularity} = \frac{4 \pi \times \text{Area}}{\text{Perimeter}^2} ]
These features are scaled using StandardScaler before being passed into the neural network.
After training on the custom dataset:
precision recall f1-score support
Circle 1.00 1.00 1.00 1303
Square 1.00 1.00 1.00 1181
Triangle 1.00 1.00 1.00 664
accuracy 1.00 3148
macro avg 1.00 1.00 1.00 3148
weighted avg 1.00 1.00 1.00 3148
Confusion Matrix:
[[1301 2 0]
[ 2 1179 0]
[ 0 0 664]]
This project uses the Geometric Shapes Dataset from Kaggle:
The dataset contains labeled images of circles, squares, and triangles, which were used for feature extraction and training the ANN classifier.
✅ Image Processing coursework
✅ Projects requiring traditional ML + computer vision
✅ Offline/embedded systems where deep learning is not feasible