OAR (ONNXRuntime And Rust) OCR
A comprehensive OCR (Optical Character Recognition) library, built in Rust with ONNX Runtime for efficient inference.
Quick Start
Installation
Add OAROCR to your project's Cargo.toml:
For CUDA support, add with the cuda feature:
Or manually add it to your Cargo.toml:
[]
= "0.2"
# For CUDA support
= { = "0.2", = ["cuda"] }
Basic Usage
Here's a simple example of how to use OAROCR to extract text from an image:
use *;
use Path;
This example creates an OCR pipeline using pre-trained models for text detection and recognition. The pipeline processes the input image and returns structured TextRegion objects containing the recognized text, confidence scores, and bounding boxes for each detected text region.
Using CUDA for GPU Acceleration
For better performance, you can enable CUDA support to run inference on GPU:
use *;
use ;
use Path;
Note: To use CUDA support, you need to:
- Install oar-ocr with CUDA feature:
cargo add oar-ocr --features cuda - Have CUDA toolkit and cuDNN installed on your system
- Ensure your ONNX models are compatible with CUDA execution
Pre-trained Models
OAROCR provides several pre-trained models for different OCR tasks. Download them from the GitHub Releases page.
Text Detection Models
Choose between mobile and server variants based on your needs:
- Mobile: Smaller, faster models suitable for real-time applications
- Server: Larger, more accurate models for high-precision requirements
| Model Type | Version | Category | Model File | Size | Description |
|---|---|---|---|---|---|
| Text Detection | PP-OCRv4 | Mobile | ppocrv4_mobile_det.onnx |
4.8MB | Mobile variant for real-time applications |
| Text Detection | PP-OCRv4 | Server | ppocrv4_server_det.onnx |
113.2MB | Server variant for high-precision requirements |
| Text Detection | PP-OCRv5 | Mobile | ppocrv5_mobile_det.onnx |
4.8MB | Mobile variant for real-time applications |
| Text Detection | PP-OCRv5 | Server | ppocrv5_server_det.onnx |
87.7MB | Server variant for high-precision requirements |
Text Recognition Models
Recognition models are available in multiple versions and languages:
Chinese/General Models
| Model Type | Version | Language/Category | Model File | Size | Description |
|---|---|---|---|---|---|
| Text Recognition | PP-OCRv4 | Chinese/General | ppocrv4_mobile_rec.onnx |
10.8MB | Mobile variant |
| Text Recognition | PP-OCRv4 | Chinese/General | ppocrv4_server_rec.onnx |
90.4MB | Server variant |
| Text Recognition | PP-OCRv4 | Chinese/General | ppocrv4_server_rec_doc.onnx |
94.7MB | Server variant for document text |
| Text Recognition | PP-OCRv5 | Chinese/General | ppocrv5_mobile_rec.onnx |
16.5MB | Mobile variant |
| Text Recognition | PP-OCRv5 | Chinese/General | ppocrv5_server_rec.onnx |
84.1MB | Server variant |
Language-Specific Models
| Model Type | Version | Language | Model File | Size | Description |
|---|---|---|---|---|---|
| Text Recognition | PP-OCRv4 | English | en_ppocrv4_mobile_rec.onnx |
7.7MB | Language-specific model |
| Text Recognition | PP-OCRv5 | Eastern Slavic | eslav_ppocrv5_mobile_rec.onnx |
7.9MB | Language-specific model |
| Text Recognition | PP-OCRv5 | Korean | korean_ppocrv5_mobile_rec.onnx |
13.4MB | Language-specific model |
| Text Recognition | PP-OCRv5 | Latin | latin_ppocrv5_mobile_rec.onnx |
7.9MB | Language-specific model |
Character Dictionaries
Character dictionaries are required for text recognition models. Choose the appropriate dictionary for your models:
General Dictionaries
| File Type | Version | Category | Model File | Size | Description |
|---|---|---|---|---|---|
| Character Dictionary | PP-OCRv4 | Document | ppocrv4_doc_dict.txt |
- | For PP-OCRv4 document models |
| Character Dictionary | PP-OCRv5 | General | ppocrv5_dict.txt |
- | For PP-OCRv5 models |
| Character Dictionary | PP-OCR Keys v1 | General | ppocr_keys_v1.txt |
- | For older PP-OCR models |
Language-Specific Dictionaries
| File Type | Version | Language | Model File | Size | Description |
|---|---|---|---|---|---|
| Character Dictionary | PP-OCRv4 | English | en_dict.txt |
- | For PP-OCRv4 English recognition models |
| Character Dictionary | PP-OCRv5 | Eastern Slavic | ppocrv5_eslav_dict.txt |
- | For PP-OCRv5 Eastern Slavic models |
| Character Dictionary | PP-OCRv5 | Korean | ppocrv5_korean_dict.txt |
- | For PP-OCRv5 Korean models |
| Character Dictionary | PP-OCRv5 | Latin | ppocrv5_latin_dict.txt |
- | For PP-OCRv5 Latin script models |
Optional Models
These models provide additional functionality for specialized use cases:
| Model Type | Version | Category | Model File | Size | Description |
|---|---|---|---|---|---|
| Document Orientation | PPLCNet | - | pplcnet_x1_0_doc_ori.onnx |
6.7MB | Detect document rotation |
| Text Line Orientation | PPLCNet | Light | pplcnet_x0_25_textline_ori.onnx |
988KB | Detect text line orientation |
| Text Line Orientation | PPLCNet | Standard | pplcnet_x1_0_textline_ori.onnx |
6.7MB | Detect text line orientation |
| Document Rectification | UVDoc | - | uvdoc.onnx |
31.6MB | Fix perspective distortion |
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.