# glcrealm/optical-character-recognition architecture

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

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

## Overview

##### Main Components
a. **User Interface (UI)**
- Script: `compleat.py`
- Built on Python with `customtkinter`
b. **OCR Core / Application Logic**
- Preprocessing & helper functions: `firstuse.py`
- Segmentation & Tesseract integration: `ocr6.py`
c. **Machine Learning Model**
- Serialized neural network: `first_model.pkl` (TensorFlow/Keras)
d. **External Engine**
- Tesseract OCR binary (external dependency invoked by `pytesseract`)
e. **Data Sources**
- Input images (via GUI “Import”)
- Test dataset folder (for validation)
f. **Supporting Libraries & Environment**
- Python 3.x, `numpy`, `Pillow`, `customtkinter`, `pytesseract`, `tensorflow`, `pickle`

##### Relationships & Data Flows
1. **User Action** → GUI layer (`compleat.py`) receives image file.
2. **Image Preprocessing** → GUI calls functions in `firstuse.py` (thresholding, resizing).
4. **Tesseract OCR** → For baseline extraction or to handle whitespace/line breaks, `pytesseract` calls Tesseract binary.
5. **Deep Learning Prediction** → Each segmented character tile fed into `first_model.pkl` via TensorFlow API.
6. **Aggregation** → Recognized characters are concatenated into strings.
8. **Optional** → Test dataset can be piped through the same pipeline for batch evaluation.

##### Architectural Patterns & Design Principles
- **Modular Separation**: UI separated from OCR logic and ML model.
- **Pipeline Pattern**: Sequential stages (preprocessing → segmentation → prediction → display).
- **Dependency Injection**: External Tesseract path is configurable in `ocr6.py`.

##### Additional Details to Capture
- Configuration point: Tesseract path in `ocr6.py`.
- ML framework: TensorFlow (version if known).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["compleat.py\n(Import, Predict, Cancel)"]:::ui
    end

    %% Application Logic Layer
    subgraph "Application Logic Layer"
        Pre["firstuse.py\n(Preprocessing & Helpers)"]:::processing
        Seg["ocr6.py\n(Segmentation & Tesseract Integration)"]:::processing
    end

    %% Data & External Layer
    subgraph "Data & External Layer"
        Model["first_model.pkl\n(Serialized Neural Network)"]:::data
        TestData["test dataset\n(Batch Evaluation)"]:::data
        Tesseract["Tesseract Binary\n(External OCR Engine)"]:::external
        Env["requirments.txt\n(Environment & Dependencies)"]:::data
    end

    %% Data Flows
    UI -->|"Import Image"| Pre
    Pre -->|"call preprocess_image()"| Seg
    Seg -->|"invoke pytesseract"| Tesseract
    Seg -->|"feed char tiles"| Model
    Tesseract -->|"baseline OCR text"| Seg
    Model -->|"predicted chars"| Seg
    Seg -->|"aggregate text"| UI
    TestData -->|"batch input"| Pre

    %% Click Events
    click UI "https://github.com/glcrealm/optical-character-recognition/blob/main/Optical Character Recognigion/complete.py"
    click Pre "https://github.com/glcrealm/optical-character-recognition/blob/main/Optical Character Recognigion/firstuse.py"
    click Seg "https://github.com/glcrealm/optical-character-recognition/blob/main/Optical Character Recognigion/ocr6.py"
    click Model "https://github.com/glcrealm/optical-character-recognition/blob/main/Optical Character Recognigion/first_model.pkl"
    click TestData "https://github.com/glcrealm/optical-character-recognition/tree/main/Optical Character Recognigion/test dataset"
    click Env "https://github.com/glcrealm/optical-character-recognition/blob/main/Optical Character Recognigion/requirments.txt"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef processing fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef data fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
