Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
RustO! ๐ฆ
Pure Rust OCR Library - Fast, Safe, and Cross-Platform
RustO! is a high-performance OCR (Optical Character Recognition) library written in pure Rust, based on RapidOCR and powered by PaddleOCR models with MNN inference engine.
๐ฏ Why RustO!?
- ๐ Pure Rust - Zero OpenCV dependency, optional OpenCV backend available
- ๐ฏ High Accuracy - 99.3% parity with OpenCV-based implementations
- โก Fast Performance - Optimized with LTO, single codegen unit compilation
- ๐ Memory Safe - Leverages Rust's safety guarantees
- ๐ Cross-Platform - Linux, macOS, Windows, iOS, Android support
- ๐ง FFI Ready - C FFI bindings for integration with other languages
- ๐ฆ Easy to Use - Simple API, modern CLI with JSON/Text/TSV output
๐๏ธ Architecture
RustO! is built on top of proven OCR technology:
- Based on: RapidOCR architecture
- Models: PaddleOCR PPOCRv4/v5 models
- Inference: MNN inference engine for high-performance cross-platform execution
- Image Processing: Pure Rust implementation (image + imageproc crates)
- Contour Detection: Custom Rust implementation matching OpenCV behavior
๐ Project Structure
rusto-rs/
โโโ src/
โ โโโ lib.rs # Public API
โ โโโ main.rs # CLI application
โ โโโ ffi.rs # C FFI bindings (optional)
โ โโโ det.rs # Text detection
โ โโโ rec.rs # Text recognition
โ โโโ layout.rs # Layout detection
โ โโโ doc_pipeline.rs # Document pipeline (layout + OCR)
โ โโโ preprocess.rs # Image preprocessing
โ โโโ postprocess.rs # Result postprocessing
โ โโโ contours.rs # Pure Rust contour detection
โ โโโ geometry.rs # Geometric transformations + NMS
โ โโโ image_impl.rs # Image abstraction layer
โ โโโ ...
โโโ Cargo.toml # Dependencies & optimization
โโโ docs/ # Documentation
โโโ examples/ # Example applications
โ โโโ doc_pipeline_demo.rs # Document pipeline example
โ โโโ ...
โโโ packages/ # Additional packages
Model Conversion
RustO! uses MNN inference engine. You need to convert PaddleOCR models to MNN format:
# Install required tools
# Download and build MNN from https://github.com/alibaba/MNN
# Convert models using the provided script
See MODEL_CONVERSION.md for detailed conversion instructions.
Quick Start
1. Build the Library
# Pure Rust build (default)
# With FFI bindings
# With OpenCV backend (optional)
2. Run CLI Application
# JSON output (default)
# Plain text output
# TSV output
3. Use as a Library
Add to your Cargo.toml:
[]
= "0.1"
Then in your code:
use ;
4. Document Pipeline (Layout + OCR)
RustO! now supports document layout analysis combined with OCR for structured document processing:
use ;
Supported Layout Elements:
- Text, Title, Header, Footer
- Figure, Figure Caption
- Table, Table Caption
- Reference, Equation
Example:
5. iOS Integration
Install via CocoaPods:
pod ,
Then in Swift:
import RustO
let ocr = try RapidOCR(
detModelPath: Bundle.main.path(forResource: "det", ofType: "mnn")!,
recModelPath: Bundle.main.path(forResource: "rec", ofType: "mnn")!,
dictPath: Bundle.main.path(forResource: "dict", ofType: "txt")!
)
let results = try ocr.recognizeFile("image.jpg")
for result in results {
print("\(result.text): \(result.score)")
}
API Reference
RapidOCRConfig
Configuration structure for initializing the OCR engine.
TextResult
OCR result for a single detected text region.
RapidOCR
Main OCR engine.
FFI Bindings
The library includes C FFI bindings for integration with other languages. Enable with the ffi feature:
This produces:
- Linux:
librusto.so - macOS:
librusto.dylib - Windows:
rusto.dll
See src/ffi.rs for the complete FFI API documentation.
๐ฆ Models
RustO! uses PaddleOCR models converted to ONNX format:
Supported Models
- PPOCRv4 - PaddleOCR version 4 models
- PPOCRv5 - PaddleOCR version 5 models (recommended)
Model Components
- Detection Model (
det.onnx) - Detects text regions in images - Recognition Model (
rec.onnx) - Recognizes text within detected regions - Dictionary (
dict.txt) - Character dictionary for text recognition
Download Models
# Example: Download PPOCRv5 models
โก Performance
Benchmarks
Tested on typical document images:
| Metric | Value |
|---|---|
| Detection | ~80ms |
| Recognition (per box) | ~120ms |
| Total (28 boxes) | ~3.5s |
| Memory Peak | ~200MB |
Comparison with OpenCV-based implementations
| Aspect | RustO! | OpenCV-based |
|---|---|---|
| Speed | โ Similar (ยฑ10%) | Baseline |
| Accuracy | โ 99.3% parity | 100% |
| Binary Size | โ Smaller | Larger (OpenCV deps) |
| Memory Usage | โ Lower | Higher (OpenCV overhead) |
| Dependencies | โ Minimal | OpenCV required |
| Safety | โ Memory safe | Manual memory management |
Configuration
Cargo Features
[]
= [] # Pure Rust mode
= ["opencv"] # Use OpenCV backend
= [] # Enable C FFI bindings
Build Profiles
[]
= 3 # Maximum optimization
= "fat" # Link-time optimization
= 1 # Single codegen unit for better optimization
= true # Strip symbols
= "abort" # Smaller binary
Development
Run Tests
Run Benchmarks
Check Code
Known Issues
Rust Library (contours.rs)
- โ ๏ธ Unused functions (400+ lines) - cleanup pending
- โ ๏ธ Minor lint warnings - non-blocking
Remaining Parity Gap (0.7%)
- 2 minor text differences out of 28 boxes
- Caused by: Spacing (
"Gol. Darah:"vs"Gol. Darah :") - Impact: Negligible for production use
License
MIT (or your license)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
cargo test - Submit a pull request
Support
- ๐ง Email: support@rapidocr.com
- ๐ฌ Discussions: GitHub Discussions
- ๐ Issues: GitHub Issues
๐ Acknowledgments
RustO! builds upon the excellent work of:
- RapidOCR - Architecture and design inspiration
- PaddleOCR - State-of-the-art OCR models (PPOCRv4/v5)
- ONNX Runtime - Cross-platform inference engine
- Rust Community - Excellent tooling and libraries (image, imageproc, nalgebra)
๐ Citation
If you use RustO! in your research or project, please cite:
Also consider citing the underlying technologies:
- PaddleOCR: https://github.com/PaddlePaddle/PaddleOCR
- RapidOCR: https://github.com/RapidAI/RapidOCR
Status: Production Ready ๐
Version: 0.1.4
License: MIT
Made with โค๏ธ and ๐ฆ Rust