MCPcopy Index your code
hub / github.com/GreatV/oar-ocr

github.com/GreatV/oar-ocr @v0.7.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.7.3 ↗ · + Follow
2,816 symbols 7,068 edges 208 files 1,165 documented · 41%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

OAR-OCR

Crates.io Version Crates.io Downloads (recent) dependency status GitHub License

An Optical Character Recognition (OCR) and Document Layout Analysis library written in Rust.

Quick Start

Installation

cargo add oar-ocr

With GPU support:

cargo add oar-ocr --features cuda

With auto-download of model files from ModelScope:

cargo add oar-ocr --features auto-download

Bare file names passed to the builders are then fetched from ModelScope into $OAR_HOME (default ~/.oar) and verified against their expected SHA-256. See docs/models.md for the exact path resolution rules.

Basic Usage

use oar_ocr::prelude::*;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the OCR pipeline
    let ocr = OAROCRBuilder::new(
        "pp-ocrv5_mobile_det.onnx",
        "pp-ocrv5_mobile_rec.onnx",
        "ppocrv5_dict.txt",
    )
    .build()?;

    // Load an image
    let image = load_image(Path::new("document.jpg"))?;

    // Run prediction
    let results = ocr.predict(vec![image])?;

    // Process results
    for text_region in &results[0].text_regions {
        if let Some((text, confidence)) = text_region.text_with_confidence() {
            println!("Text: {} ({:.2})", text, confidence);
        }
    }

    Ok(())
}

PP-OCRv6

PP-OCRv6 ships in three sizes. Pass the bare file names below and enable the auto-download feature to fetch them automatically or point to local paths:

Size Detection Recognition Dictionary
tiny pp-ocrv6_tiny_det.onnx pp-ocrv6_tiny_rec.onnx ppocrv6_tiny_dict.txt
small pp-ocrv6_small_det.onnx pp-ocrv6_small_rec.onnx ppocrv6_dict.txt
medium pp-ocrv6_medium_det.onnx pp-ocrv6_medium_rec.onnx ppocrv6_dict.txt
use oar_ocr::prelude::*;
use oar_ocr::domain::tasks::TextDetectionConfig;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // PP-OCRv6 "tiny" — swap in small/medium (with ppocrv6_dict.txt) for higher accuracy.
    let ocr = OAROCRBuilder::new(
        "pp-ocrv6_tiny_det.onnx",
        "pp-ocrv6_tiny_rec.onnx",
        "ppocrv6_tiny_dict.txt",
    )
    // Official PP-OCRv6 detection defaults.
    .text_detection_config(TextDetectionConfig {
        score_threshold: 0.2,
        box_threshold: 0.45,
        unclip_ratio: 1.4,
        ..Default::default()
    })
    .build()?;

    let image = load_image(Path::new("document.jpg"))?;
    let results = ocr.predict(vec![image])?;

    for region in &results[0].text_regions {
        if let Some((text, confidence)) = region.text_with_confidence() {
            println!("{text}  ({confidence:.2})");
        }
    }

    Ok(())
}

Document Structure Analysis

use oar_ocr::prelude::*;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize structure analysis pipeline
    let structure = OARStructureBuilder::new("pp-doclayout_plus-l.onnx")
        .with_table_classification("pp-lcnet_x1_0_table_cls.onnx")
        .with_table_structure_recognition("slanet_plus.onnx", "wireless")
        .table_structure_dict_path("table_structure_dict_ch.txt")
        .with_ocr(
            "pp-ocrv5_mobile_det.onnx", 
            "pp-ocrv5_mobile_rec.onnx", 
            "ppocrv5_dict.txt"
        )
        .build()?;

    // Analyze document
    let result = structure.predict("document.jpg")?;

    // Output Markdown
    println!("{}", result.to_markdown());

    Ok(())
}

Vision-Language Models (VLM)

For advanced document understanding using Vision-Language Models (like PaddleOCR-VL, PaddleOCR-VL-1.5, PaddleOCR-VL-1.6, GLM-OCR, HunyuanOCR, and MinerU2.5), check out the oar-ocr-vl crate.

Documentation

Examples

The examples/ directory contains complete examples for various tasks:

# General OCR
cargo run --example ocr -- --help

# Document Structure Analysis
cargo run --example structure -- --help

# Layout Detection
cargo run --example layout_detection -- --help

# Table Structure Recognition
cargo run --example table_structure_recognition -- --help

Acknowledgments

This project builds upon the excellent work of several open-source projects:

  • ort: Rust bindings for ONNX Runtime by pykeio. This crate provides the Rust interface to ONNX Runtime that powers the efficient inference engine in this OCR library.

  • PaddleOCR: Baidu's awesome multilingual OCR toolkits based on PaddlePaddle. This project utilizes PaddleOCR's pre-trained models, which provide excellent accuracy and performance for text detection and recognition across multiple languages.

  • Candle: A minimalist ML framework for Rust by Hugging Face. We use Candle to implement Vision-Language model inference.

Extension points exported contracts — how you extend this code

ModelAdapter (Interface)
Core trait for model adapters. Adapters bridge the gap between task interfaces and concrete model implementations. They [11 …
oar-ocr-core/src/core/traits/adapter.rs
EdgeProcessor (Interface)
Trait for processors that transform data between task nodes. [5 implementers]
src/oarocr/processors.rs
RecognitionBackend (Interface)
Trait for recognition backends that can process cropped regions. [4 implementers]
oar-ocr-vl/src/doc_parser.rs
TaskDefinition (Interface)
Trait for compile-time task registration. Implemented by each task's output type to provide metadata for enum generatio [11 …
oar-ocr-core/src/core/traits/task_def.rs
Task (Interface)
Core trait for OCR tasks. Tasks represent distinct operations in the OCR pipeline (detection, recognition, etc.). Each [11 …
oar-ocr-core/src/core/traits/task.rs
AdapterBuilder (Interface)
Builder trait for creating model adapters. This trait defines the interface for building adapters with specific configu [5 …
oar-ocr-core/src/core/traits/adapter.rs
OrtConfigurable (Interface)
Trait for adapter builders that support ONNX Runtime session configuration. This trait is implemented by builders that [5 …
oar-ocr-core/src/core/traits/adapter.rs

Core symbols most depended-on inside this repo

iter
called by 742
oar-ocr-core/src/core/config/transform.rs
len
called by 546
oar-ocr-core/src/core/batch/mod.rs
candle_to_ocr_inference
called by 509
oar-ocr-vl/src/utils.rs
is_empty
called by 376
oar-ocr-core/src/core/batch/mod.rs
candle_to_ocr_processing
called by 303
oar-ocr-vl/src/utils.rs
x_min
called by 156
oar-ocr-core/src/processors/geometry.rs
y_min
called by 154
oar-ocr-core/src/processors/geometry.rs
into_iter
called by 136
oar-ocr-core/src/core/config/transform.rs

Shape

Method 1,296
Function 1,065
Class 380
Enum 52
Interface 23

Languages

Rust100%

Modules by API surface

oar-ocr-core/src/domain/structure.rs93 symbols
src/oarocr/structure.rs76 symbols
oar-ocr-core/src/domain/adapters/layout_detection_adapter.rs56 symbols
src/oarocr/stitching.rs54 symbols
examples/utils/visualization.rs48 symbols
oar-ocr-core/src/utils/image.rs47 symbols
oar-ocr-core/src/processors/geometry.rs47 symbols
oar-ocr-vl/src/utils.rs46 symbols
oar-ocr-vl/src/mineru_diffusion/model.rs41 symbols
src/oarocr/table_analyzer.rs40 symbols
oar-ocr-core/src/core/inference/tensor_output.rs39 symbols
oar-ocr-vl/src/mineru/model.rs38 symbols

For agents

$ claude mcp add oar-ocr \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page