# krishnaharesh/optical-character-recognition architecture

> Architecture diagram of the GitHub repository krishnaharesh/optical-character-recognition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishnaharesh/optical-character-recognition
- Repository: https://github.com/krishnaharesh/optical-character-recognition

## Overview

This repository is a comparative OCR study with three independent command-line implementations: MNIST digit classification using an SVM, handwritten text recognition using TrOCR, and zero-shot transcription using an Ollama vision-language model. Each follows its own image or dataset-to-prediction path; only the deep-learning script computes character-level metrics and displays a dashboard. The README describes a broader cross-method evaluation, but the sampled code does not show a shared comparison runner, so that capability is represented as documented rather than as an implemented integration.

Main entry points: [`Deep Learning Approach/app.py`](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py) (Image loading and TrOCR inference), [`README.md`](https://github.com/krishnaharesh/optical-character-recognition/blob/main/README.md) (Comparative evaluation), [`Machine Learning Appraoch/main.py`](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py) (SVM training and prediction), [`LLM Approach/main.py`](https://github.com/krishnaharesh/optical-character-recognition/blob/main/LLM%20Approach/main.py) (Image preparation and prompt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ml["Machine Learning OCR"]
  node_mnist[("MNIST data<br/>[main.py]")]
  node_svm["SVM training and prediction<br/>[main.py]"]
  node_mlmetrics["Classification metrics and samples<br/>[main.py]"]
end

subgraph group_deep["Deep Learning OCR"]
  node_dlimage["Image loading and TrOCR inference<br/>[app.py]"]
  node_trocr["Pretrained TrOCR model<br/>[app.py]"]
  node_dlmetrics["Character metrics<br/>[app.py]"]
  node_dashboard["OCR results dashboard<br/>[app.py]"]
end

subgraph group_llm["LLM OCR"]
  node_llmprep["Image preparation and prompt<br/>[main.py]"]
  node_ollama{{"Ollama vision inference"}}
  node_transcription["Transcription output<br/>[main.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_comparison["Comparative evaluation<br/>[README.md]"]
end

node_user(("Image user"))

node_user -->|"provides image"| node_dlimage
node_user -->|"provides image"| node_llmprep
node_mnist -->|"trains and tests"| node_svm
node_svm -->|"evaluates predictions"| node_mlmetrics
node_dlimage -->|"runs inference"| node_trocr
node_trocr -->|"supplies prediction"| node_dlmetrics
node_dlmetrics -->|"supplies metrics"| node_dashboard
node_dlimage -->|"supplies image and text"| node_dashboard
node_llmprep -->|"sends image and prompt"| node_ollama
node_ollama -->|"returns transcription"| node_transcription
node_mlmetrics -.->|"contributes evaluation"| node_comparison
node_dlmetrics -.->|"contributes evaluation"| node_comparison
node_transcription -.->|"contributes evaluation"| node_comparison

click node_mnist "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py"
click node_svm "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py"
click node_mlmetrics "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py"
click node_dlimage "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py"
click node_trocr "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py"
click node_dlmetrics "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py"
click node_dashboard "https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py"
click node_llmprep "https://github.com/krishnaharesh/optical-character-recognition/blob/main/LLM%20Approach/main.py"
click node_transcription "https://github.com/krishnaharesh/optical-character-recognition/blob/main/LLM%20Approach/main.py"
click node_comparison "https://github.com/krishnaharesh/optical-character-recognition/blob/main/README.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mnist,node_svm,node_mlmetrics,node_user toneBlue
class node_dlimage,node_trocr,node_dlmetrics,node_dashboard toneAmber
class node_llmprep,node_ollama,node_transcription toneMint
class node_comparison toneRose
```

## Components

### Machine Learning OCR

- [MNIST data](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py): `Machine Learning Appraoch/main.py`
- [SVM training and prediction](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py): `Machine Learning Appraoch/main.py`
- [Classification metrics and samples](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Machine%20Learning%20Appraoch/main.py): `Machine Learning Appraoch/main.py`

### Deep Learning OCR

- [Image loading and TrOCR inference](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py): `Deep Learning Approach/app.py`
- [Pretrained TrOCR model](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py): `Deep Learning Approach/app.py`
- [Character metrics](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py): `Deep Learning Approach/app.py`
- [OCR results dashboard](https://github.com/krishnaharesh/optical-character-recognition/blob/main/Deep%20Learning%20Approach/app.py): `Deep Learning Approach/app.py`

### LLM OCR

- [Image preparation and prompt](https://github.com/krishnaharesh/optical-character-recognition/blob/main/LLM%20Approach/main.py): `LLM Approach/main.py`
- **Ollama vision inference**
- [Transcription output](https://github.com/krishnaharesh/optical-character-recognition/blob/main/LLM%20Approach/main.py): `LLM Approach/main.py`

### Evaluation

- [Comparative evaluation](https://github.com/krishnaharesh/optical-character-recognition/blob/main/README.md): `README.md`

### Other components

- **Image user**

## Connections

- Image user → Image loading and TrOCR inference: provides image (evidence: `README.md`)
- Image user → Image preparation and prompt: provides image (evidence: `README.md`)
- MNIST data → SVM training and prediction: trains and tests (evidence: `Machine Learning Appraoch/main.py`)
- SVM training and prediction → Classification metrics and samples: evaluates predictions (evidence: `Machine Learning Appraoch/main.py`)
- Image loading and TrOCR inference → Pretrained TrOCR model: runs inference (evidence: `Deep Learning Approach/app.py`)
- Pretrained TrOCR model → Character metrics: supplies prediction (evidence: `Deep Learning Approach/app.py`)
- Character metrics → OCR results dashboard: supplies metrics (evidence: `Deep Learning Approach/app.py`)
- Image loading and TrOCR inference → OCR results dashboard: supplies image and text (evidence: `Deep Learning Approach/app.py`)
- Image preparation and prompt → Ollama vision inference: sends image and prompt (evidence: `LLM Approach/main.py`)
- Ollama vision inference → Transcription output: returns transcription (evidence: `LLM Approach/main.py`)
- Classification metrics and samples → Comparative evaluation: contributes evaluation (evidence: `README.md`)
- Character metrics → Comparative evaluation: contributes evaluation (evidence: `README.md`)
- Transcription output → Comparative evaluation: contributes evaluation (evidence: `README.md`)
