# plleopart/ocr_video_analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/plleopart/ocr_video_analyzer
- Repository: https://github.com/plleopart/ocr_video_analyzer

## Overview

##### Project Type & Purpose
- This is a command-line OCR-based video analyzer application. Its main purpose is to process video files by extracting text from predefined regions using Tesseract OCR.
- The project supports configuration (via an INI file), region validation, and processing video frames, with extracted text output saved to disk.

##### Analyzing the File Structure
- Top-Level Files:
- main.py: This is the entry point where the application starts. It likely handles user prompts (e.g., selecting video, configuration, processing options).
- example.config.ini: A sample configuration file outlining OCR settings, coordinates, etc.
- requirements.txt and README.md: Standard for dependency management and documentation.
- “ocr” Directory:
- __init__.py: Marks the directory as a Python package.
- ocr_manager.py: Likely centralizes the orchestration logic of video processing and text extraction.
- slicer.py: Probably responsible for slicing the video into frames or selecting specific regions defined in the configuration.
- storage.py: Handles saving the processed OCR results to the file system (e.g., output directory with timestamped subfolders).

##### Reading the README for Additional Insights
- The README confirms that the user will interact with the system via a command-line menu, choose different operations (configure, validate regions, process video), and that configuration parameters are crucial for text extraction.
- It mentions external dependencies such as OpenCV, Tesseract OCR, and others, which are integral to the architectural flow (video processing to OCR engine, then output handling).

##### Key Components
a. Main Application Layer:
- main.py: The control layer that handles user input and directs operations.
b. OCR Processing Modules (in the “ocr” package):
- OCR Manager (ocr_manager.py): Acts as the central coordinator. It likely calls on the slicer and storage.
- Video Slicer (slicer.py): Handles frame extraction and region segmentation.
- Storage Module (storage.py): Saves the OCR results into designated output files.
c. Configuration Component:
- Config.ini (or the example file): Holds all OCR and region data. This feeds into the OCR Manager.
d. External Dependencies:
- Tesseract OCR: For performing text recognition.
- OpenCV and NumPy: For video frame processing and image manipulation.
- Rich: For an enhanced terminal UI.
e. I/O/Data Layers:
- Input: Video files placed in the specified source directory (even if not in the file tree, it’s mentioned in the README).
- Output: Processed results saved in a structured output directory (timestamped subfolder with .dat files).

##### Relationships & Interactions
- The system starts at main.py, which prompts the user for actions.
- Based on user choice:
- The configuration and region selection is loaded from or written to the config file.
- The OCR Manager (in ocr_manager.py) is invoked. It coordinates with:
▪ The Slicer (slicer.py) that extracts video frames according to the defined regions.
▪ The Storage component (storage.py), which persists the extracted text in separate data files.
- The config settings and dependencies (via requirements.txt) should be clearly denoted as influencing the behavior of the OCR Manager and its submodules.

##### Architectural Patterns, Design Principles, and Technologies
- The project uses a modular structure with a clear separation of concerns:
- Input/Output handling (main.py, storage.py).
- Core business logic and coordination (ocr_manager.py).
- Video processing and region-based extraction (slicer.py).
- Technology highlights include:
- Python programming language.
- Tesseract for OCR.
- OpenCV and NumPy for video/image processing.
- Rich library for terminal UI improvements.
- The project architecture is simple but follows a layered design where each component has a well-defined responsibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    VI["Video File Input"]:::input
    M["main.py (Entry Point)"]:::app
    CF["example.config.ini"]:::config
    OM["OCR Manager"]:::ocr
    VS["Video Slicer"]:::ocr
    SM["Storage Module"]:::io
    T["Tesseract OCR"]:::external
    OC["OpenCV"]:::external
    NP["NumPy"]:::external
    R["Rich (Terminal UI)"]:::external
    OF["Output Files"]:::output

    VI -->|"provides_video"| M
    M -->|"orchestrates"| OM
    CF -->|"provides_config"| OM
    OM -->|"calls_slicer"| VS
    OM -->|"calls_storage"| SM
    VS -->|"invokes_OCR"| T
    T -->|"returns_text"| OM
    SM -->|"writes_results"| OF
    VS -.->|"uses"| OC
    VS -.->|"uses"| NP
    M -.->|"enhances_UI"| R

    click M "https://github.com/plleopart/ocr_video_analyzer/blob/main/main.py"
    click CF "https://github.com/plleopart/ocr_video_analyzer/blob/main/example.config.ini"
    click OM "https://github.com/plleopart/ocr_video_analyzer/blob/main/ocr/ocr_manager.py"
    click VS "https://github.com/plleopart/ocr_video_analyzer/blob/main/ocr/slicer.py"
    click SM "https://github.com/plleopart/ocr_video_analyzer/blob/main/ocr/storage.py"

    classDef app fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef config fill:#ff9966,stroke:#333,stroke-width:2px;
    classDef ocr fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef io fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#e6e6e6,stroke:#333,stroke-width:2px;
    classDef input fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef output fill:#d9b3ff,stroke:#333,stroke-width:2px;
```
