How genggode/libocr works
Project type and purpose
• This is a C++ library (no GUI) exposing a simple C‐style API for OCR.
• Purpose: provide offline, embedded OCR via ONNX models without heavy dependencies.
File structure
• Top‐level:
• include/libocr – public headers
• source/ – core implementation, subdivided into:
‑ image/ (image loading/manipulation)
‑ onnx/text_detector (ONNX‑based text detection)
‑ onnx/text_recognizer (ONNX‑based text recognition)
‑ ocr/ (low‑level OCR functions)
‑ ocr_manager/ (high‑level orchestration)
• resource/ – embedded ONNX models, dictionaries, embedding utilities
• test/ – example clients demonstrating dynamic/static linkage
README for insights
• Libraries used: ONNX Runtime, optionally OpenCV (found via CMake scripts).
• Build via CMake + vcpkg, outputs libocr.dll/.lib.
• Public API: libocr::ocr_file(...), libocr::free_char(...).
Main components & interactions
a. Client Application
• Calls ocr_file() → receives raw image path.
b. Image Module
• Loads image (OpenCV or custom loader).
c. OCR Manager
• Coordinates detection & recognition stages.
d. ONNX Subsystems
• Text Detector: runs model_det.onnx to find text regions.
• Text Recognizer: runs model_rec.onnx + model_rec_dict.txt to decode text.
e. Resource Embedding
• Embeds model files into binary via resource/embed_resource.cpp.
f. ONNX Runtime & Other Dependencies
• Linked via CMake (find_onnxruntime.cmake), possibly OpenCV (find_opencv.cmake).
Architectural patterns & principles
• Modular layering:
• Public API layer (libocr.h)
• Core orchestration (ocr_manager)
• Specialized modules (image, detector, recognizer)
• Dependency inversion: clients depend on API, not implementation.
• Embedded resources: static bundling of models for zero‐setup usage.