How dungcan2k5/imath_ocrix works
Project Type and Purpose
• This is a standalone Python desktop application (“OCR_Project”) whose purpose is to capture regions of the screen (snip), run OCR on plain text or on mathematical formulas (including Vietnamese text support), and present the results to the user.
File-Structure Analysis
Top-level files and directories:
• app.py – main entry point; GUI or CLI orchestration
• snip_screen.py – screen‐capture service
• img_OCR.py & img_OCR_func.py
• math_OCR.py & math_OCR_func.py
• .py – shared constants, config for OCR engines
• Imath Ocrix.py – specialized math OCR orchestrator (possibly using a third‐party engine)
• Img_temp/ – temporary storage for captured image snippets
• __pycache__/ – bytecode cache
README Insights
• Description: “Quét văn bản và công thức toán học trong hình ảnh có hỗ trợ tiếng Việt”
• Confirms dual OCR pipelines (text + math) and Vietnamese language requirement.
Main Components
– Presents buttons to “capture screen,” “run text OCR,” “run math OCR,” and displays results.
b. Service (snip_screen.py)
– Grabs a user‐selected region, writes to Img_temp/, returns image path.
c. Preprocessing & Routing (define.py + app.py logic)
– Applies any image preprocessing (e.g., binarization), decides which OCR pipeline to invoke.
d. Text OCR Pipeline (img_OCR.py + img_OCR_func.py)
– Uses Tesseract or similar via a wrapper to extract Vietnamese text.
e. Math OCR Pipeline (Imath Ocrix.py + math_OCR.py + math_OCR_func.py)
– Calls a math‐specialized engine (e.g., Mathpix API or custom model) to parse formulas; outputs LaTeX or Unicode.
f. Temp-File Store (Img_temp/)
– Holds intermediate PNG/JPEG files; cleaned up after processing.
g. External Dependencies
– Tesseract OCR engine, any math‐OCR SDK or web API, Python imaging libraries (Pillow/OpenCV).
Interactions & Data Flow
1. User clicks “Snip” → UI triggers snip_screen.py → capture → save to Img_temp/ → return image object.
2. UI (app.py) applies define.py settings → chooses pipeline.
3. If Text OCR: pass image to img_OCR.py → calls img_OCR_func.py → invokes Tesseract → raw text.
4. If Math OCR: pass image to math_OCR.py → calls math_OCR_func.py + Imath Ocrix.py → math engine → LaTeX/formula output.
6. Optionally delete temp image or archive in Img_temp/.
Architectural Patterns & Principles
• Single Responsibility: each module handles one concern (capture vs text OCR vs math OCR vs UI)
• Modular Pipelines: separate “text” and “math” flows, share only common preprocessing
• Configuration Abstraction: define.py centralizes engine parameters (language, DPI, thresholds)