# abdelhak2406/ocr_project architecture

> Architecture diagram of the GitHub repository abdelhak2406/ocr_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdelhak2406/ocr_project
- Repository: https://github.com/abdelhak2406/ocr_project

## Overview

##### Project Type and Purpose
- This is a standalone desktop OCR (Optical Character Recognition) application written in Python.
- It provides a GUI for users to load images, applies pre-processing (binarisation & filtering), and then runs OCR to extract text.

##### File-Structure Analysis
- Top-level:
- src/main.py – application entry point (initializes GUI and application logic)
- requirements.txt – Python dependencies (likely including PyQt5, Pillow/OpenCV, pytesseract)
- src/app: core image-processing modules
- binarisation.py – converts image to binary (thresholding)
- filtrage.py – applies filtering (noise removal, smoothing)
- src/gui: GUI definition
- main_ocr.ui – Qt Designer XML layout
- main_ocr_ui.py – generated Python UI class
- No backend server or database – it’s a single-process desktop app.

##### Key Components
a. User Interface (UI) Layer
– Component: “GUI” (Qt)
– Sources: main_ocr.ui, main_ocr_ui.py, triggered by src/main.py
b. Application Core Layer
– Components:
- Image Loader (file I/O)
- Binarisation Module (src/app/binarisation.py)
- Filtering Module (src/app/filtrage.py)
- OCR Engine (external, e.g., pytesseract or Tesseract CLI)
– The core modules form a pipeline: Loader → Binarisation → Filtering → OCR
c. External Dependencies
– Tesseract OCR (or other engine)
– Python Libraries (PyQt5, Pillow/OpenCV)
d. Environment & Packaging
– Conda/Venv environment (requirements.txt)
– Entry point: src/main.py

##### Relationships & Data Flows
- User triggers “Open Image” in GUI →
GUI calls Image Loader →
Loaded image object passed to Binarisation →
Binarised image passed to Filtering →
Filtered image passed to OCR Engine →
OCR Engine returns text →
GUI displays recognized text.
- Configuration/Dependencies flow (side-channel): requirements.txt → environment → application runtime.

##### Architectural Patterns & Design Principles
- Separation of concerns: UI layer versus processing layer.
- Pipeline pattern for image processing.
- Modular design: each processing step is in its own module.
- Single‐process, synchronous flow (no microservices).

3. Below it, arrange the pipeline: File I/O → Binarisation → Filtering → OCR Engine.
4. At the far right, place “OCR Engine (pytesseract/Tesseract)”.
5. GUI to File I/O and then chain the pipeline.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Python 3.8 / Conda Env"
        classDef ui fill:#add8e6,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5;
        classDef core fill:#90ee90,stroke:#000,stroke-width:1px;
        classDef io fill:#d3d3d3,stroke:#000,stroke-width:1px;
        classDef ext fill:#ffa500,stroke:#000,stroke-width:1px;

        ENTRY["Entry Point\n(main.py)"]:::io
        GUI["GUI (Qt)"]:::ui
        IO["Image Loader\n(File I/O)"]:::io
        BIN["Binarisation\n(binarisation.py)"]:::core
        FIL["Filtering\n(filtrage.py)"]:::core
        OCR["OCR Engine\n(pytesseract/Tesseract)"]:::ext

        ENTRY --> GUI
        GUI --> IO
        IO --> BIN
        BIN --> FIL
        FIL --> OCR
        OCR -->|"display text"| GUI
    end

    REQ["requirements.txt"]:::io
    REQ -.-> ENTRY

    click ENTRY "https://github.com/abdelhak2406/ocr_project/blob/main/src/main.py"
    click GUI "https://github.com/abdelhak2406/ocr_project/blob/main/src/gui/main_ocr.ui"
    click GUI "https://github.com/abdelhak2406/ocr_project/blob/main/src/gui/main_ocr_ui.py"
    click BIN "https://github.com/abdelhak2406/ocr_project/blob/main/src/app/binarisation.py"
    click FIL "https://github.com/abdelhak2406/ocr_project/blob/main/src/app/filtrage.py"
    click OCR "https://github.com/abdelhak2406/ocr_project/blob/main/src/main.py"

    class ENTRY,IO,REQ io
    class GUI ui
    class BIN,FIL core
    class OCR ext
```
