OCR in Python using k-Nearest Neighbors (k-NN) to recognize characters of the Yoruba alphabet
# K-Nearest Neighbors for OCR
๐ Read this in other languages:
- ๐ง๐ท Portuguรชs
In this project, we use the k-Nearest Neighbors (k-NN) algorithm to perform automatic recognition of characters from the Yoruba alphabet based on preprocessed images. This process falls within the context of OCR ( Optical Character Recognition ) , where the goal is to identify the character represented by an image. KNN was chosen for being a simple, interpretable, and effective method for similarity-based classification problems.
## Participants
Artur Massaro Cremonez
Bruno Henrique Silva Viola
---
## What was done?
We started with image preprocessing, converting the images to grayscale. We implemented an option to crop the white borders around the characters (this option can be enabled via a flag). Finally, the images were resized to `32x32` pixels.
---
## Repository Structure
Additional experiments were carried out using different image resolutions (`16x16`, `64x64`, `128x128`, etc.). The results can be found in the following folders:
- ๐ `matrizes_de_confusao/`
- ๐ `metricas_por_classe/`
- ๐ `relatorios_classificacao/`
---
## Methodology
- ๐ Algorithm: `KNeighborsClassifier` with `k=5`
- ๐ Execution over **10 iterations** using different random seeds
- ๐ Data split: **80% training / 20% testing**
- ๐ Images flattened before being fed into the model
### Evaluation Metrics
Two categories of metrics were evaluated:
- ๐ **Overall metrics (averaged after 10 iterations):**
- Accuracy
- Precision
- Recall
- F1-Score
- ๐ **Per-class metrics:**
- Precision per class
- Recall per class
- F1-Score per class
---
## Pipeline
### โถ๏ธ Preprocessing
- Conversion to grayscale
- Options:
- Color normalization
- Dimension normalization
- Class balancing (via data augmentation)
- Data organization by class
### โถ๏ธ Training / Testing
- Execution of KNN over 10 iterations
- Recording metrics per iteration and per class
- Saving result files in `.txt`, `.png`, etc.
### โถ๏ธ Post-process โฆ