High-Precision Local OCR Pipeline: Technical Documentation

This pipeline is designed for high-fidelity document content extraction, transforming raw images or PDFs into structured Markdown and, optionally, schema-compliant JSON.

1. Input Data Preparation and Optimization

Before the OCR process begins, the system performs automated preprocessing to maximize model readability:

  • Image Optimization: For image files (e.g., JPG, PNG), the system automatically adjusts the black point, brightness, and contrast.
  • Hybrid PDF Processing: Digital PDFs are processed directly. Because the service classifies each page individually, mixed documents (containing both scanned and digital pages) are processed seamlessly.
  • Scan Correction: Scans are rendered at 200 DPI. PP-LCNet detects page rotation in 90-degree increments, followed by UVDoc for geometric dewarping to minimize perspective distortion. If automatic correction fails, the original page is passed into the processing chain to ensure uninterrupted document flow.

2. Layout Analysis and Reading Order Definition

The system merges two specialized detection models to establish a consistent reading order:

  • Detectors: PP-DocLayoutV3 (general structure) and Docling Layout Heron (high-precision table detection).
  • Merge Logic: Heron-identified table regions take absolute priority. Remaining regions are integrated based on compatibility and size (largest first).
  • Overlap Constraints: Overlaps are strictly controlled using normalized page coordinates. An overlap is only permissible if it is below 1% of the page dimensions along the overlap axis and respects specific relative thresholds: maximum 18% for text regions and 5% for structured regions (tables). Full containment is also treated as an overlap.

3. Text Recognition and Complex Table Reconstruction

3.1 Text Regions

For the extraction of body text, the MinerU2.5-Pro-2605-1.2B (Q8_0) model is used. The system employs intelligent error recovery: if a region returns an empty response, an automatic retry is triggered by reducing the image crop by one pixel per edge and increasing brightness (×1.1) and contrast (×1.2). This retry applies to crops from both scanned and digital sources.

3.2 Table Reconstruction

Table processing occurs in three phases:

  1. Grid Proposal: The table is isolated and oriented. PP-LCNet classifies it as bordered or borderless. While SLANet Plus proposes a grid by default, UnetStructure is additionally employed for bordered tables, cases where classifier confidence is below 90%, or when SLANet detects fewer than four cells.
  2. Line Detection: PP-OCRv6 Small scans the entire table area independently of the proposed grid. Every recognized four-corner text box is mathematically straightened into a dedicated crop for MinerU.
  3. HTML Synthesis and Ranking: Extracted lines are assigned to cells via spatial positioning. The system generates reconstruction candidates, including a version created by grouping lines vertically into rows and sorting them left-to-right. Candidates are ranked by penalizing those that collapse to a single row or column, then favoring those with more rows, then more columns, and finally higher cell occupancy. If structured reconstruction fails, the entire table is passed to MinerU as a fallback.

4. Structured Data Extraction via LLM

Once the content is available as Markdown (including HTML tables), an optional transformation into a machine-readable format is performed using Gemma 4 26B-A4B IT.

To maximize reliability, the system utilizes:

  • Deterministic Output: Zero temperature and "no-thinking" mode to prevent hallucinations.
  • Schema-Constraint Decoding: Using llama.cpp grammar-constrained decoding, the model is technically restricted to generating only characters that conform to the provided JSON schema (keys, types, and formats).
  • Validation and Retry Logic: A separate parser validates the generated JSON. In case of errors, empty fields, or malformed data, a bounded retry is triggered with a corrective prompt containing the original OCR Markdown.

5. Outputs and Diagnostics

The system delivers the finished Markdown (with HTML tables), structured content blocks, and the complete layout metadata (original and fused). For auditing and optimization, a Diagnostic ZIP is generated, providing all intermediate image crops and raw model responses to trace recognition failures.

References and Model Downloads

Stage Reference Direct Download
Page Orientation PP-LCNet document orientation ONNX
Page Dewarping UVDoc ONNX
General Layout PP-DocLayoutV3 Safetensors
Table Layout Docling Layout Heron Safetensors
Table Classification PP-LCNet table classifier ONNX
Table Grid SLANet Plus ONNX
Framed Table Grid MinerU UnetStructure ONNX
Table Line Detection PP-OCRv6 Small Safetensors
OCR Recognition MinerU2.5-Pro GGUF Q8_0 Weights · Vision Projector
Structured Extraction Gemma 4 26B-A4B IT GGUF UD-Q6_K Weights · MTP Draft Model

*Note for manual setup: Please download the associated configuration files (inference.yml, config.json, preprocessor_config.json) along with the model weights.

Edit

Pub: 01 Dec 2026 21:27 UTC

Views: 74