# gmkrxb/xiaoyuankousuan architecture

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

- Interactive diagram: https://gitdiagram.com/gmkrxb/xiaoyuankousuan
- Repository: https://github.com/gmkrxb/xiaoyuankousuan

## Overview

##### Main Components
- Main Application (main.py): This is the entry point where the GUI is launched, input parameters (e.g., number of questions, timing, regions for capturing numbers) are set, and the overall control flow is coordinated.
- OCR Engine Integration: The system integrates with Tesseract OCR (and has a module for comparison with easyocr). This part is responsible for processing the captured image and returning recognized digits.
- Coordinate Capture Module (get_xy.py): A utility component to obtain mouse coordinates, which are used to define regions from which screenshots will be taken.
- Comparison Module (comparison.py): A helper script to test and compare recognition results and performance between different OCR libraries.
- Assets and Temporary Storage: The static image (bg.png) used for background filling in the GUI, and the "temp" folder which stores the images captured or segmented during processing.
- Test Resource (test_photo.png): Used for testing and validating OCR performance.

##### Relationships and Data Flow
- The “main.py” serves as the central coordinator. When the user initiates the process, it triggers:
- The coordinate capture module (get_xy.py) to obtain regions from the screen.
- The OCR pipeline where Tesseract (or easyocr, as tested via comparison.py) takes the screenshot (optionally from the "temp" directory) and runs recognition.
- The assets (bg.png and possibly temporary images in the "temp" folder) are used by the GUI rendering part of the application.

##### Architectural Patterns and Key Points
- Modular Design: The application is separated into distinct files each managing specific tasks (main application logic, OCR comparison/benchmarking, and coordinate capture).
- Environment Configuration: Although not a runtime component, the installation instructions for Tesseract and library dependencies can be noted as “external dependencies” that need to be configured for the system to work properly.

##### Additional Details
- Mention that the “temp” folder is a runtime-generated asset where image segmentation results are stored, reinforcing that the system dynamically creates and utilizes temporary data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    subgraph "User Interaction"
        U("User"):::external
    end

    %% Core Application Modules
    subgraph "Core Application"
        MainApp("GUI Controller"):::core
        Coord("Mouse Coordinate Utility"):::utility
        OCR("OCR Processing Engine"):::core
        Draw("Result Rendering"):::core
    end

    %% Asset Modules
    subgraph "Assets"
        Bg("Background Image"):::asset
        Temp("Temporary Storage (temp)"):::asset
        Test("Test Resource"):::asset
    end

    %% Development/Testing Tools
    subgraph "Development Tools"
        Comparison("OCR Comparison Module"):::aux
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Tesseract("Tesseract OCR"):::external
        EasyOCR("EasyOCR"):::external
        Libs("Python Libraries: pyautogui, opencv-python, pillow, numpy"):::external
    end

    %% Data Flow
    U -->|"initiates"| MainApp
    MainApp -->|"defines capture region"| Coord
    Coord -->|"returns coordinates"| MainApp
    MainApp -->|"captures screenshot into"| Temp
    Temp -->|"provides screenshot to"| OCR
    OCR -->|"processes image with"| Tesseract
    OCR -->|"or processes alternatively with"| EasyOCR
    OCR -->|"produces OCR result"| MainApp
    MainApp -->|"renders result (>,<,=) using"| Draw
    MainApp -->|"loads asset"| Bg
    Comparison -->|"benchmarks OCR results"| OCR
    MainApp -->|"utilizes"| Libs
    OCR -->|"utilizes"| Libs

    %% Styles
    classDef core fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef utility fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef asset fill:#bbdefb,stroke:#1565c0,stroke-width:2px;
    classDef external fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
    classDef aux fill:#d1c4e9,stroke:#512da8,stroke-width:2px;

    %% Click Events
    click MainApp "https://github.com/gmkrxb/xiaoyuankousuan/blob/main/main.py"
    click Coord "https://github.com/gmkrxb/xiaoyuankousuan/blob/main/get_xy.py"
    click Comparison "https://github.com/gmkrxb/xiaoyuankousuan/blob/main/comparison.py"
```
