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 PP-OCRv6 (Default), PP-OCRv5, PP-OCRv4, and PP-OCRv3 models
- Inference: MNN inference engine for high-performance cross-platform execution on mobile, desktop, and server
- 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 & exports
โ โโโ config.rs # RustOConfig, presets (PPV6, PPV5, PPV4, PPV3), & builders
โ โโโ main.rs # CLI application
โ โโโ ffi.rs # C FFI bindings
โ โโโ det.rs # Text detection (DBNet)
โ โโโ rec.rs # Text recognition (CTC)
โ โโโ orient.rs # Document orientation classification
โ โโโ layout.rs # Layout detection
โ โโโ table.rs # Table recognition & HTML structure
โ โโโ 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
โ โโโ types.rs # Type definitions, Frame, & Config structures
โโโ models/
โ โโโ PPOCR_v6/ # PP-OCRv6 MNN models (Tiny prebundled, Small, Medium)
โ โโโ PPOCR_v5/ # PP-OCRv5 MNN models
โโโ packages/
โ โโโ react-native/ # React Native TypeScript + iOS/Android bindings
โ โโโ android/ # Android library (Kotlin/JNI)
โ โโโ ios/ # iOS Swift package / CocoaPod
โ โโโ dotnet/ # .NET C# NuGet package
โโโ ...
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 Rust Library
Add to your Cargo.toml:
[]
= "0.1"
Then in your code:
use ;
4. Template Presets & Architecture Support
RustO! provides pre-configured template presets for different PaddleOCR model generations:
use ;
// PP-OCRv6 (Default): limit_side_len=736, min, det_thresh=0.3, det_box_thresh=0.6, unclip=2.0
let v6_config = ppv6;
// PP-OCRv5: limit_side_len=736, min, det_thresh=0.3, det_box_thresh=0.5, unclip=2.0
let v5_config = ppv5;
// PP-OCRv4: limit_side_len=960, max, det_thresh=0.3, det_box_thresh=0.6, unclip=1.5
let v4_config = ppv4;
// PP-OCRv3: limit_side_len=960, max, det_thresh=0.3, det_box_thresh=0.6, unclip=1.5
let v3_config = ppv3;
5. Cross-Platform SDKs
React Native
import { initialize, detectText, detectTextToSpatialText } from 'react-native-rusto';
// Initialize with bundled default PP-OCRv6 tiny models (no parameters needed!)
await initialize();
// Detect text with bounding frames
const results = await detectText('/path/to/image.jpg');
results.forEach((r) => {
console.log(`${r.text} (${r.score}) - Frame:`, r.frame); // { width, height, top, left }
});
// Or format directly to spatial layout text
const spatialText = await detectTextToSpatialText('/path/to/image.jpg', 0.5, 1.0);
console.log(spatialText);
iOS (Swift)
import RustO
// Default PP-OCRv6 configuration
let config = RustOConfig.ppv6(
det: "det.mnn",
rec: "rec.mnn",
dict: "dict.txt"
)
let ocr = try RustO(config: config)
let results = try ocr.recognizeFile("image.jpg")
for result in results {
print("\(result.text) (\(result.score)): frame=\(result.frame.left),\(result.frame.top),\(result.frame.width)x\(result.frame.height)")
}
Android (Kotlin)
import com.byrizki.rusto.RustO
import com.byrizki.rusto.RustOConfig
val config = RustOConfig(
template = "ppv6",
detModelPath = "det.mnn",
recModelPath = "rec.mnn",
dictPath = "dict.txt"
)
val ocr = RustO(context, config)
val results = ocr.recognizeFile("/path/to/image.jpg")
.NET (C#)
using RustODotnet;
var config = RustOConfig.Ppv6("det.mnn", "rec.mnn", "dict.txt");
using var ocr = new RustO(config);
var results = ocr.RecognizeFile("image.jpg");
API Reference
RustOConfig & Builders
Comprehensive configuration structure supporting granular parameter overrides:
let config = ppv6
// Detection tuning
.with_det_thresh
.with_det_box_thresh
.with_limit_side_len
.with_limit_type
.with_unclip_ratio
.with_use_dilation
.with_max_candidates
.with_score_mode
// Recognition tuning
.with_rec_img_shape
.with_rec_batch_num
// Global & Spatial tuning
.with_text_score
.with_xy_threshold
.with_min_height
.with_max_side_len
// Optional modules
.with_cls
.with_orientation
.with_unwarp;
Frame & TextResult
๐ฆ Models
RustO! uses lightweight, high-performance PaddleOCR models in MNN format:
Model Series Supported
- PP-OCRv6 (Default & Recommended) โ MetaFormer-based PPLCNetV4 architecture with 50-language unified dictionary. Available in Tiny (prebundled, 6.0 MB total), Small, and Medium tiers.
- PP-OCRv5 โ High-accuracy detection with SVTR-LCNet recognition.
- PP-OCRv4 โ Lightweight mobile OCR models.
- PP-OCRv3 โ Legacy mobile OCR models.
Downloading Pre-Converted MNN Models
Official models are hosted on ModelScope RapidAI/RapidOCR:
# PP-OCRv6 Tiny (Prebundled default)
๐ C FFI & Shared Libraries
RustO! provides a high-performance C FFI interface for building desktop, mobile, and native bindings. Enable with the ffi feature:
This compiles shared libraries:
- Linux:
target/release/librusto.so - macOS / iOS:
target/release/librusto.dylib - Windows:
target/release/rusto.dll
FFI APIs include rocr_new_with_config(config_json), rocr_run(inst, image_path), rocr_run_to_spatial_text(inst, image_path, y_multiplier, x_multiplier), and direct memory pointer interfaces.
โก 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.7
License: MIT
Made with โค๏ธ and ๐ฆ Rust