← All projects

Handwritten Letter Classifier

A convolutional neural network that classifies handwritten letters from real photos with the OpenCV preprocessing pipeline

  • python
  • pytorch
  • opencv
  • streamlit

software2026

The Streamlit app: an uploaded photo of a handwritten letter beside the model's prediction and confidence scores.

Problem

A CNN trained on EMNIST hits ~93% on EMNIST’s clean test set, then falls apart on a phone photo: shadows, uneven lighting, and arbitrary framing look nothing like the training data.

How it was solved

The model is deliberately simple. The real work is the OpenCV pipeline that turns a photo into what the model expects: adaptive thresholding, which judges each pixel against its local neighborhood and so survives uneven light, then contour detection to find the letter and reject shadow edges, then crop, pad, and center to EMNIST’s framing.

When confidence is low the app says so, because the model has no “not a letter” class.

Results

~93% on clean test data, lower on real uploads: the documented gap. Remaining confusions are the genuinely ambiguous pairs (i/l, g/q), which are near-identical in isolation. A data ceiling, not a tuning problem.