panhg/oar-ocr
模型介绍文件和版本Pull Requests讨论分析

OAR-OCR

OAR-OCR 为 Rust 库 oar-ocr 提供基于 Paddle 的 OCR 及文档解析模型资源。本 ModelScope 仓库托管运行时自动下载功能所使用的 ONNX 模型、词典、分词器和结构分析文件。

包含资源

  • 来自 PaddleOCR 系列的文本检测、识别、方向和印章模型。
  • 用于页面结构分析的文档布局和区块布局模型。
  • 表格分类、单元格检测和表格结构识别模型。
  • 公式识别模型和分词器文件。
  • OCR 流程所需的共享词典和配置文件。

快速使用

添加 Rust crate:

cargo add oar-ocr --features auto-download

当启用 auto-download 时,已注册的裸文件名会从 ModelScope 上的 greatv/oar-ocr 获取到 $OAR_HOME(默认路径为 ~/.oar),并在使用前进行验证。

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(())
}

文档结构

该结构处理流程整合了 Paddle 布局检测、OCR、表格识别、公式识别及印章检测功能,以生成类 Markdown 格式的文档输出。

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(())
}

注意事项

本仓库中的模型文件作为 Paddle 框架资源提供,并由 Rust 实现通过 ONNX Runtime 进行使用。有关详细的模型列表、哈希值以及高级用法,请参阅 GitHub 仓库中的项目文档。

下载使用量0