Logo Lanfrica

BrunoViola/ocr-with-knn

Domain:

natural language processing

Record type:

software
Creator:
Bru
Host:
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 โ€ฆ