oar-ocr

43 downloads 2 likes on ModelScope updated

Model card

OAR-OCR

OAR-OCR provides Paddle-based OCR and document parsing model assets for the Rust oar-ocr library. This ModelScope repository hosts ONNX models, dictionaries, tokenizers, and structure-analysis files used by the runtime auto-download feature.

Included Assets

  • Text detection, recognition, orientation, and seal models from the PaddleOCR family.
  • Document layout and block layout models for page structure analysis.
  • Table classification, cell detection, and table structure recognition models.
  • Formula recognition models and tokenizer files.
  • Shared dictionaries and configuration files required by the OCR pipeline.

Quick Use

Add the Rust crate:

cargo add oar-ocr --features auto-download

When auto-download is enabled, registered bare file names are fetched from greatv/oar-ocr on ModelScope into $OAR_HOME (default ~/.oar) and verified before use.

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ocr = OAROCRBuilder::new(
        "pp-ocrv5_mobile_det.onnx",
        "pp-ocrv5_mobile_rec.onnx",
        "ppocrv5_dict.txt",
    )
    .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, score)) = region.text_with_confidence() {
            println!("{text} ({score:.2})");
        }
    }

    Ok(())
}

Document Structure

The structure pipeline combines Paddle layout detection, OCR, table recognition, formula recognition, and seal detection to produce Markdown-like document output.

use oar_ocr::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let structure = OARStructureBuilder::new("pp-doclayout_plus-l.onnx")
        .with_ocr(
            "pp-ocrv5_mobile_det.onnx",
            "pp-ocrv5_mobile_rec.onnx",
            "ppocrv5_dict.txt",
        )
        .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")
        .build()?;

    let result = structure.predict("document.jpg")?;
    println!("{}", result.to_markdown());

    Ok(())
}

Notes

The model files in this repository are served as Paddle-framework assets and are consumed through ONNX Runtime by the Rust implementation. For detailed model lists, hashes, and advanced usage, see the project documentation in the GitHub repository.