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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div align="center">
|
| 2 |
+
|
| 3 |
+
# RustO! π¦
|
| 4 |
+
|
| 5 |
+
**High-Performance, Pure Rust OCR Engine & Multi-Platform Toolkit**
|
| 6 |
+
|
| 7 |
+
[](https://crates.io/crates/rusto-rs)
|
| 8 |
+
[](https://docs.rs/rusto-rs)
|
| 9 |
+
[](https://pypi.org/project/rusto/)
|
| 10 |
+
[](https://www.npmjs.com/package/@rustors/node)
|
| 11 |
+
[](https://www.npmjs.com/package/@rustors/react-native)
|
| 12 |
+
[](https://pub.dev/packages/rusto)
|
| 13 |
+
[](https://pub.dev/packages/rusto_flutter)
|
| 14 |
+
[](https://www.nuget.org/packages/RustODotnet)
|
| 15 |
+
[](https://cocoapods.org/pods/RustO)
|
| 16 |
+
[](https://jitpack.io/#byrizki/rusto-rs)
|
| 17 |
+
[](https://byrizki.com/rusto-rs/)
|
| 18 |
+
[](https://github.com/byrizki/rusto-rs/actions/workflows/ci.yml)
|
| 19 |
+
[](https://github.com/byrizki/rusto-rs/actions/workflows/docs-ci.yml)
|
| 20 |
+
[](https://github.com/byrizki/rusto-rs/actions/workflows/build.yml)
|
| 21 |
+
[](https://opensource.org/licenses/MIT)
|
| 22 |
+
[](https://snyk.io/test/github/byrizki/rusto-rs)
|
| 23 |
+
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
**RustO!** is a pure-Rust Optical Character Recognition (OCR) engine and multi-platform toolkit. Powered by PaddleOCR models and the [RTen](https://github.com/robertknight/rten) inference engine (`.rten` & `.onnx`), RustO! delivers fast, memory-safe text extraction with zero C++ or OpenCV dependencies.
|
| 27 |
+
|
| 28 |
---
|
| 29 |
+
|
| 30 |
+
## π― Key Features
|
| 31 |
+
|
| 32 |
+
- **Pure Rust Engine** β Zero C++ or OpenCV runtime dependencies. Build directly with `cargo build`.
|
| 33 |
+
- **Fast & Lightweight** β SIMD-accelerated inference, ~5.4 MB CLI binary, and ~85β120 MB peak RAM.
|
| 34 |
+
- **PP-OCR Model Tiers** β PP-OCRv6 (50+ languages unified), PP-OCRv5, and PP-OCRv4 (FP32 & INT8).
|
| 35 |
+
- **Document Layouts** β Outputs bounding boxes, line/word tokens, or formatted 2D spatial text layouts.
|
| 36 |
+
- **Cross-Platform SDKs** β First-class libraries for Rust, Web (WASM), React, React Native, iOS, Android, and .NET.
|
| 37 |
+
|
| 38 |
---
|
| 39 |
+
|
| 40 |
+
## π¦ Packages
|
| 41 |
+
|
| 42 |
+
| Platform | Package | Description |
|
| 43 |
+
|---|---|---|
|
| 44 |
+
| **Rust** | [`cargo add rusto-rs`](https://crates.io/crates/rusto-rs) | Pure Rust library and CLI |
|
| 45 |
+
| **Node.js (N-API)** | [`@rustors/node`](https://www.npmjs.com/package/@rustors/node) | Native Node.js N-API addon |
|
| 46 |
+
| **Python** | [`pip install rusto`](https://pypi.org/project/rusto) | UniFFI Python library & wheel |
|
| 47 |
+
| **Golang** | [`packages/go`](https://pkg.go.dev/github.com/byrizki/rusto-rs/packages/go) | Cgo Go module with embedded rpath |
|
| 48 |
+
| **Java (JVM)** | [`rusto-java`](https://jitpack.io/#byrizki/rusto-rs) (`com.github.byrizki.rusto-rs:rusto-java`) | Java & Kotlin JNA library via JitPack |
|
| 49 |
+
| **Dart** | [`rusto`](https://pub.dev/packages/rusto) | Pure Dart FFI library |
|
| 50 |
+
| **Flutter** | [`rusto_flutter`](https://pub.dev/packages/rusto_flutter) | Flutter plugin with Android & iOS bridges |
|
| 51 |
+
| **Web (WASM)** | [`@rustors/web`](https://www.npmjs.com/package/@rustors/web) | Browser-native WASM engine |
|
| 52 |
+
| **React** | [`@rustors/react`](https://www.npmjs.com/package/@rustors/react) | React hooks and components |
|
| 53 |
+
| **React Native** | [`@rustors/react-native`](https://www.npmjs.com/package/@rustors/react-native) | iOS and Android native bridge |
|
| 54 |
+
| **iOS** | `Package.swift` / [`pod 'RustO'`](https://cocoapods.org/pods/RustO) | Swift Package Manager & CocoaPods |
|
| 55 |
+
| **Android** | [`rusto-android`](https://jitpack.io/#byrizki/rusto-rs) | Kotlin library & AAR |
|
| 56 |
+
| **.NET / C#** | [`RustODotnet`](https://www.nuget.org/packages/RustODotnet) | Managed .NET library |
|
| 57 |
+
| **C / Native** | `librusto.so` / `.dylib` / `.dll` | C FFI shared libraries |
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## β οΈ Notable Breaking Changes in v0.3.0
|
| 62 |
+
|
| 63 |
+
Upgrading from **v0.2.x** to **v0.3.0** transitions the core engine to pure Rust with zero C++ toolchain dependencies:
|
| 64 |
+
|
| 65 |
+
| Aspect | v0.2.x | v0.3.0 (Current) |
|
| 66 |
+
|---|---|---|
|
| 67 |
+
| **Inference Engine** | Alibaba MNN (requires C++ / CMake) | **Pure Rust RTen** (zero native toolchain) |
|
| 68 |
+
| **Model Formats** | Proprietary `.mnn` models | High-performance **`.rten`** (FlatBuffers) or **`.onnx`** |
|
| 69 |
+
| **Session API** | `MnnSession` | **`EngineSession`** (pluggable `InferenceSession`) |
|
| 70 |
+
| **Configuration** | Nested `preprocessing` block | Decoupled **`InitializeConfig`** & **`OcrRunOptions`** |
|
| 71 |
+
| **NPM Scope** | Standalone names (`react-rusto`, etc.) | Unified **`@rustors/*`** scope |
|
| 72 |
+
|
| 73 |
+
π **[Read the Complete v0.2 β v0.3 Migration Guide](https://byrizki.com/rusto-rs/en/advance-guide/migration-guide)** for code comparisons, API changes, and step-by-step instructions.
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## π Quick Start by Language
|
| 78 |
+
|
| 79 |
+
### 1. Rust
|
| 80 |
+
|
| 81 |
+
```rust
|
| 82 |
+
use rusto::{ImageSource, InitializeConfig, OcrRunOptions, RustO};
|
| 83 |
+
|
| 84 |
+
let mut ocr = RustO::initialize(InitializeConfig::ppv6("det.rten", "rec.rten", "dict.txt"))?;
|
| 85 |
+
let result = ocr.detect_text(&ImageSource::Path("document.jpg".into()), &OcrRunOptions::default())?;
|
| 86 |
+
println!("{result:?}");
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
### 2. .NET / C#
|
| 92 |
+
|
| 93 |
+
```csharp
|
| 94 |
+
using RustODotnet;
|
| 95 |
+
|
| 96 |
+
using var ocr = RustO.Initialize(InitializeConfig.Ppv6());
|
| 97 |
+
var result = ocr.DetectText(new UriImageSource("invoice.jpg"), new OcrRunOptions());
|
| 98 |
+
|
| 99 |
+
if (result is StructuredDetectTextResult structured) {
|
| 100 |
+
foreach (var item in structured.Items) {
|
| 101 |
+
Console.WriteLine($"{item.Text} ({item.Score:F2})");
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
---
|
| 107 |
+
|
| 108 |
+
### 3. Web (WASM / Browser)
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
npm install @rustors/web
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
```typescript
|
| 115 |
+
import { initialize, detectText } from '@rustors/web';
|
| 116 |
+
|
| 117 |
+
await initialize({
|
| 118 |
+
preset: 'ppv6',
|
| 119 |
+
models: {
|
| 120 |
+
detection: '/models/ppocrv6-tiny/det.rten',
|
| 121 |
+
recognition: '/models/ppocrv6-tiny/rec.rten',
|
| 122 |
+
dictionary: '/models/ppocrv6-tiny/dict.txt',
|
| 123 |
+
},
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
const results = await detectText(document.querySelector('img')!);
|
| 127 |
+
results.forEach((r) => console.log(`${r.text} (${r.score})`));
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
### 4. React
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
npm install @rustors/react @rustors/web
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
```tsx
|
| 139 |
+
import { RustoProvider, useOcr } from '@rustors/react';
|
| 140 |
+
|
| 141 |
+
const models = {
|
| 142 |
+
detection: '/models/ppocrv6-tiny/det.rten',
|
| 143 |
+
recognition: '/models/ppocrv6-tiny/rec.rten',
|
| 144 |
+
dictionary: '/models/ppocrv6-tiny/dict.txt',
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
function OcrScanner() {
|
| 148 |
+
const { detect, results, isProcessing } = useOcr();
|
| 149 |
+
|
| 150 |
+
return (
|
| 151 |
+
<div>
|
| 152 |
+
<input type="file" onChange={(e) => e.target.files?.[0] && detect(e.target.files[0])} />
|
| 153 |
+
{isProcessing && <p>Scanning...</p>}
|
| 154 |
+
{results.map((r, i) => <p key={i}>{r.text} ({r.score.toFixed(2)})</p>)}
|
| 155 |
+
</div>
|
| 156 |
+
);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
export function App() {
|
| 160 |
+
return (
|
| 161 |
+
<RustoProvider config={{ preset: 'ppv6', models }}>
|
| 162 |
+
<OcrScanner />
|
| 163 |
+
</RustoProvider>
|
| 164 |
+
);
|
| 165 |
+
}
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
### 5. React Native
|
| 171 |
+
|
| 172 |
+
```bash
|
| 173 |
+
npm install @rustors/react-native
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
```typescript
|
| 177 |
+
import { initialize, detectText } from '@rustors/react-native';
|
| 178 |
+
|
| 179 |
+
await initialize();
|
| 180 |
+
const results = await detectText({ uri: 'file:///path/to/image.jpg' });
|
| 181 |
+
results.forEach((r) => console.log(`${r.text} (${r.score})`));
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
---
|
| 185 |
+
|
| 186 |
+
### 6. iOS (Swift)
|
| 187 |
+
|
| 188 |
+
```swift
|
| 189 |
+
let ocr = try RustO.initialize(config: .ppv6())
|
| 190 |
+
let result = try ocr.detectText(.uri("receipt.jpg"))
|
| 191 |
+
|
| 192 |
+
if case .structured(let items) = result {
|
| 193 |
+
items.forEach { print("\($0.text) (\($0.score))") }
|
| 194 |
+
}
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
### 7. Android (Kotlin)
|
| 200 |
+
|
| 201 |
+
```kotlin
|
| 202 |
+
RustO.initialize(context).use { ocr ->
|
| 203 |
+
val result = ocr.detectText(ImageSource.Uri("/path/to/image.jpg"))
|
| 204 |
+
if (result is DetectTextResult.Structured) {
|
| 205 |
+
result.items.forEach { println("${it.text} (${it.score})") }
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
---
|
| 211 |
+
|
| 212 |
+
---
|
| 213 |
+
|
| 214 |
+
### 8. Node.js (N-API)
|
| 215 |
+
|
| 216 |
+
```bash
|
| 217 |
+
npm install @rustors/node
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
```javascript
|
| 221 |
+
const { RustO } = require('@rustors/node');
|
| 222 |
+
|
| 223 |
+
const engine = new RustO(JSON.stringify({
|
| 224 |
+
detection: { model_path: 'models/PPOCR_v6/det.rten' },
|
| 225 |
+
recognition: { model_path: 'models/PPOCR_v6/rec.rten', dict_path: 'models/PPOCR_v6/dict.txt' }
|
| 226 |
+
}));
|
| 227 |
+
|
| 228 |
+
const results = engine.detectTextFile('invoice.png', JSON.stringify({}));
|
| 229 |
+
results.forEach(r => console.log(`${r.text} (${(r.score * 100).toFixed(1)}%)`));
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
---
|
| 233 |
+
|
| 234 |
+
### 9. Python (UniFFI)
|
| 235 |
+
|
| 236 |
+
```bash
|
| 237 |
+
pip install rusto
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
```python
|
| 241 |
+
from rusto import RustO, InitializeConfig, OcrRunOptions
|
| 242 |
+
from rusto.generated.rusto import ImageSource
|
| 243 |
+
|
| 244 |
+
engine = RustO.initialize(InitializeConfig.ppv6("det.rten", "rec.rten", "dict.txt"))
|
| 245 |
+
result = engine.detect_text(ImageSource.PATH("invoice.png"), OcrRunOptions())
|
| 246 |
+
if result.is_STRUCTURED():
|
| 247 |
+
for item in result.results:
|
| 248 |
+
print(f"{item.text} ({item.score:.2f})")
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
---
|
| 252 |
+
|
| 253 |
+
### 10. Golang (Cgo)
|
| 254 |
+
|
| 255 |
+
```bash
|
| 256 |
+
go get github.com/byrizki/rusto-rs/packages/go
|
| 257 |
+
```
|
| 258 |
+
|
| 259 |
+
```go
|
| 260 |
+
package main
|
| 261 |
+
|
| 262 |
+
import (
|
| 263 |
+
"fmt"
|
| 264 |
+
"github.com/byrizki/rusto-rs/packages/go"
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
func main() {
|
| 268 |
+
engine, err := rusto.New(`{"detection":{"model_path":"det.rten"},"recognition":{"model_path":"rec.rten","dict_path":"dict.txt"}}`)
|
| 269 |
+
if err != nil { panic(err) }
|
| 270 |
+
defer engine.Close()
|
| 271 |
+
|
| 272 |
+
results, _ := engine.DetectTextFile("invoice.png", "{}")
|
| 273 |
+
for _, r := range results {
|
| 274 |
+
fmt.Printf("[%0.2f] %s\n", r.Score, r.Text)
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
---
|
| 280 |
+
|
| 281 |
+
### 11. Java (JVM / JNA)
|
| 282 |
+
|
| 283 |
+
```java
|
| 284 |
+
import com.byrizki.rusto.RustO;
|
| 285 |
+
import com.byrizki.rusto.TextResult;
|
| 286 |
+
|
| 287 |
+
public class App {
|
| 288 |
+
public static void main(String[] args) {
|
| 289 |
+
String config = "{\"detection\":{\"model_path\":\"det.rten\"},\"recognition\":{\"model_path\":\"rec.rten\",\"dict_path\":\"dict.txt\"}}";
|
| 290 |
+
try (RustO engine = RustO.initialize(config)) {
|
| 291 |
+
for (TextResult r : engine.detectTextFile("invoice.png", "{}")) {
|
| 292 |
+
System.out.printf("[%0.2f] %s%n", r.score(), r.text());
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
```
|
| 298 |
+
|
| 299 |
+
---
|
| 300 |
+
|
| 301 |
+
### 12. Dart & Flutter
|
| 302 |
+
|
| 303 |
+
```dart
|
| 304 |
+
import 'package:rusto/rusto.dart';
|
| 305 |
+
|
| 306 |
+
final engine = RustO.initialize('{"detection":{"model_path":"det.rten"},"recognition":{"model_path":"rec.rten","dict_path":"dict.txt"}}');
|
| 307 |
+
final results = engine.detectTextFile('invoice.png');
|
| 308 |
+
for (final line in results) {
|
| 309 |
+
print('${line.text} (${line.score})');
|
| 310 |
+
}
|
| 311 |
+
engine.close();
|
| 312 |
+
```
|
| 313 |
+
|
| 314 |
+
---
|
| 315 |
+
|
| 316 |
+
### 13. Command Line Interface (CLI)
|
| 317 |
+
|
| 318 |
+
```bash
|
| 319 |
+
# JSON output
|
| 320 |
+
cargo run --release -- --det-model det.rten --rec-model rec.rten --dict dict.txt image.jpg
|
| 321 |
+
|
| 322 |
+
# Formatted text output
|
| 323 |
+
cargo run --release -- --det-model det.rten --rec-model rec.rten --dict dict.txt --format text-ordered image.jpg
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
---
|
| 327 |
+
|
| 328 |
+
## π§ Supported OCR Models & Tiers
|
| 329 |
+
|
| 330 |
+
RustO! supports PP-OCRv6 (recognizing 50+ languages simultaneously with a unified dictionary) alongside legacy v5/v4 models:
|
| 331 |
+
|
| 332 |
+
| Tier | Standard (FP32) | Quantized (INT8) | Best For |
|
| 333 |
+
|---|:---:|:---:|---|
|
| 334 |
+
| **PP-OCRv6 Tiny** (Default) | ~6.0 MB | **~3.4 MB** | Web (WASM), mobile, IoT & embedded edge |
|
| 335 |
+
| **PP-OCRv6 Small** | ~30 MB | **~16.2 MB** | Balanced accuracy for mobile & desktop |
|
| 336 |
+
| **PP-OCRv6 Medium** | ~134 MB | **~75.7 MB** | Server-grade accuracy workloads |
|
| 337 |
+
| **PP-OCRv5 / v4** | ~23β28 MB (Mobile) | β | Legacy pipelines & single-language packs |
|
| 338 |
+
|
| 339 |
+
Pre-converted RTen models are distributed as standalone release assets on [GitHub Releases](https://github.com/byrizki/rusto-rs/releases) and downloaded automatically on first run by the CLI and native SDKs.
|
| 340 |
+
|
| 341 |
+
π **[View Complete Multilingual OCR Guide & Model Matrix](https://byrizki.com/rusto-rs/en/advance-guide/multilingual-ocr)**
|
| 342 |
+
|
| 343 |
+
---
|
| 344 |
+
|
| 345 |
+
## βοΈ Configuration & Runtime Options
|
| 346 |
+
|
| 347 |
+
RustO separates static initialization from per-request execution:
|
| 348 |
+
|
| 349 |
+
1. **`InitializeConfig`** β Configures model sessions, vocabulary dictionary, and hardware threads.
|
| 350 |
+
2. **`OcrRunOptions`** β Configures per-image options: output shape (`lines`, `words`, `spatial`), score threshold, resize bounds, and postprocessing.
|
| 351 |
+
|
| 352 |
+
```rust
|
| 353 |
+
use rusto::{InitializeConfig, OcrRunOptions, OutputGranularity, RustO};
|
| 354 |
+
|
| 355 |
+
// 1. Initialize engine once
|
| 356 |
+
let mut ocr = RustO::initialize(InitializeConfig::ppv6(
|
| 357 |
+
"models/det.rten",
|
| 358 |
+
"models/rec.rten",
|
| 359 |
+
"models/dict.txt",
|
| 360 |
+
))?;
|
| 361 |
+
|
| 362 |
+
// 2. Configure per request without mutating engine state
|
| 363 |
+
let result = ocr.detect_text(
|
| 364 |
+
&ImageSource::Path("document.jpg".into()),
|
| 365 |
+
&OcrRunOptions {
|
| 366 |
+
output: OutputGranularity::Spatial,
|
| 367 |
+
text_score: Some(0.55),
|
| 368 |
+
max_side_len: Some(1600.0),
|
| 369 |
+
..Default::default()
|
| 370 |
+
},
|
| 371 |
+
)?;
|
| 372 |
+
```
|
| 373 |
+
|
| 374 |
+
π **[Read the Full API Reference & Option Specifications](https://byrizki.com/rusto-rs/en/api-reference/ocr-run-options)**
|
| 375 |
+
|
| 376 |
+
---
|
| 377 |
+
|
| 378 |
+
## π Documentation & Advanced Guides
|
| 379 |
+
|
| 380 |
+
Explore deep-dive guides and comprehensive references on the [RustO! Documentation Site](https://byrizki.com/rusto-rs/):
|
| 381 |
+
|
| 382 |
+
| Topic | Description | Link |
|
| 383 |
+
|---|---|---|
|
| 384 |
+
| **Models & Tiers Architecture** | Model formats (`.rten`, `.onnx`), INT8 quantization, and pluggable `InferenceSession` engines | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/models-and-tiers) |
|
| 385 |
+
| **Multilingual OCR** | 50+ languages support, scripts matrix, and dedicated PP-OCRv5/v4 language packages | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/multilingual-ocr) |
|
| 386 |
+
| **Spatial Layout Reconstruction** | 2D XY spatial layout reconstruction for invoices, receipts, and multi-column tables | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/spatial-layout-reconstruction) |
|
| 387 |
+
| **Image Preprocessing & Tuning** | DBNet binarization thresholds, polygon unclipping, morphological dilation, and dimension limits | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/image-preprocessing-and-tuning) |
|
| 388 |
+
| **Multi-Column, Unwarp & Orientation** | Multi-column layout, neural reading order, 3D UVDoc unwarping, and orientation | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/multi-column-unwarp-orientation) |
|
| 389 |
+
| **Decoded RGB Input** | Zero-copy direct OCR from uncompressed interleaved RGB8 pixel buffers | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/use-decoded-rgb) |
|
| 390 |
+
| **Performance & Benchmarks** | Latency, memory footprint, and parity benchmarks across x86-64, ARM64, and mobile | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/performance-and-benchmarks) |
|
| 391 |
+
| **Troubleshooting Guide** | Resolving model paths, Android JNI linking, React Native pods, and high-resolution camera OOM | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/troubleshooting) |
|
| 392 |
+
| **v0.2 β v0.3 Migration Guide** | Upgrading to pure-Rust RTen, .rten model formats, EngineSession, and @rustors scope | [Read Guide](https://byrizki.com/rusto-rs/en/advance-guide/migration-guide) |
|
| 393 |
+
| **API Reference** | Specifications for `InitializeConfig`, `OcrRunOptions`, and `TextResult` across all platforms | [API Reference](https://byrizki.com/rusto-rs/en/api-reference/initialize-config) |
|
| 394 |
+
|
| 395 |
+
---
|
| 396 |
+
|
| 397 |
+
## β‘ Performance & Benchmarks
|
| 398 |
+
|
| 399 |
+
Empirically evaluated against official PaddleOCR and RapidOCR (C++ ONNX Runtime) using the standard **OmniDocBench** dataset and high-resolution document scans (1600Γ993 px, 27 text lines).
|
| 400 |
+
|
| 401 |
+
> **Benchmark Hardware**: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (4 cores / 8 threads), 32 GB RAM, Linux x86_64.
|
| 402 |
+
|
| 403 |
+
| Capability / Metric | RustO! (Pure Rust Core) | OpenCV / C++ Stacks (RapidOCR / PaddleOCR) | Benchmark Reference |
|
| 404 |
+
|---|:---:|:---:|---|
|
| 405 |
+
| **CLI Binary Size (Self-Contained)** | β
**5.5 MB** | β ~55 MB+ (libopencv + onnxruntime) | Production Linux x86-64 release |
|
| 406 |
+
| **C FFI Shared Library (`librusto.so`)** | β
**304 KB** | β ~15β30 MB | Stripped release `.so` |
|
| 407 |
+
| **Android Native Size (Per-ABI)** | β
**~1.8 MB** | β ~20 MB+ (`libopencv.so` + ONNX) | Android release AAR |
|
| 408 |
+
| **WebAssembly (WASM) Bundle** | β
**517 KB** (gzipped) | β 3.78 MB (gzipped ONNX Runtime WASM) | Web client bundle size |
|
| 409 |
+
| **Zero External C++ Dependencies** | β
Pure Rust (`cargo build`) | β Requires CMake, OpenCV & NDK | Toolchain build dependencies |
|
| 410 |
+
| **Peak Memory (OmniDocBench)** | β
**253.9 MB** (PP-OCRv6 Tiny) | β 392.5 MB (RapidOCR) / 659.3 MB (PaddleOCR) | OmniDocBench full dataset peak RSS |
|
| 411 |
+
| **Document Pipeline (1600Γ993 px)** | β‘ **678.08 ms** (Det: 312 ms, Rec: 169 ms, 27 lines) | β‘ 447.83 ms (C++ ONNX Runtime) | Base pipeline end-to-end benchmark |
|
| 412 |
+
| **OmniDocBench Mean Latency** | β‘ **439.18 ms** (Indra) / **1,104.41 ms** (Tiny) | β‘ 605.30 ms (PaddleOCR) / 1,011.52 ms (RapidOCR) | OmniDocBench full evaluation |
|
| 413 |
+
| **Transcription Parity (High-Res Scan)** | π― **100% token identical** across all 27 lines | π― Baseline reference | Character-for-character comparison |
|
| 414 |
+
| **OmniDocBench Baseline Accuracy (1 - NED)** | π― **45.34%** (PP-OCRv6 Tiny) | π― 45.33% (PaddleOCR Tiny) β **Ξ < 0.01%** | Standard 1D reading order |
|
| 415 |
+
| **Full Pipeline Accuracy (Reading Order)** | π― **63.75%** (RustO Indra Full) | π― 63.76% (Indra Official) / 57.18% (Paddle Structure)| Graph neural reading order |
|
| 416 |
+
| **Memory & Thread Safety** | β
Guaranteed by Rust borrow checker | β Manual pointers & thread locks | Data-race free concurrency |
|
| 417 |
+
|
| 418 |
+
---
|
| 419 |
+
|
| 420 |
+
## π Repository Structure
|
| 421 |
+
|
| 422 |
+
```
|
| 423 |
+
rusto-rs/
|
| 424 |
+
βββ src/ # Rust Core Engine
|
| 425 |
+
β βββ lib.rs # Public API & exports
|
| 426 |
+
β βββ config.rs # InitializeConfig & template presets (PPV6, PPV5, PPV4, PPV3)
|
| 427 |
+
β βββ det.rs # DBNet text detection
|
| 428 |
+
β βββ rec.rs # CTC text recognition
|
| 429 |
+
β βββ orient.rs # Orientation classification
|
| 430 |
+
β βββ preprocess.rs # Pure Rust image preprocessing & normalization
|
| 431 |
+
β βββ postprocess.rs # Polygon unpacking & spatial layout reconstruction
|
| 432 |
+
β βββ contours.rs # Pure Rust contour detection (OpenCV-free)
|
| 433 |
+
β βββ geometry.rs # Geometric transforms, box rectification & NMS
|
| 434 |
+
β βββ ffi.rs # C FFI shared library interface
|
| 435 |
+
βββ packages/
|
| 436 |
+
β βββ dotnet/ # .NET / C# SDK (RustODotnet + Model Packages)
|
| 437 |
+
β βββ react-native/ # React Native TypeScript + iOS/Android Bridge
|
| 438 |
+
β βββ android/ # Android Kotlin SDK + Modular Model AARs
|
| 439 |
+
β βββ ios/ # iOS Swift SDK + Modular Model Podspecs
|
| 440 |
+
βββ scripts/
|
| 441 |
+
β βββ download_models.sh # Direct ModelScope model downloader
|
| 442 |
+
βββ .github/workflows/
|
| 443 |
+
βββ build.yml # Parallel CI build & artifact packaging
|
| 444 |
+
βββ publish.yml # Automated multi-registry package publishing
|
| 445 |
+
```
|
| 446 |
+
|
| 447 |
+
---
|
| 448 |
+
|
| 449 |
+
## π οΈ Development & Testing
|
| 450 |
+
|
| 451 |
+
```bash
|
| 452 |
+
# Run unit & integration tests
|
| 453 |
+
cargo test
|
| 454 |
+
|
| 455 |
+
# Run tests with optional OpenCV verification backend
|
| 456 |
+
cargo test --features use-opencv
|
| 457 |
+
|
| 458 |
+
# Run benchmarks
|
| 459 |
+
cargo bench
|
| 460 |
+
|
| 461 |
+
# Run linter & formatter
|
| 462 |
+
cargo clippy
|
| 463 |
+
cargo fmt --check
|
| 464 |
+
```
|
| 465 |
+
|
| 466 |
+
---
|
| 467 |
+
|
| 468 |
+
## π‘οΈ Security & Snyk Partnership
|
| 469 |
+
|
| 470 |
+
RustO! is a community-driven open source project protected and monitored with the support of the **[Snyk Open Source Program](https://snyk.io/open-source/)**. Snyk provides automated developer security tooling to detect, track, and remediate vulnerabilities across our Rust engine, dependencies, container environments, and multi-platform packages.
|
| 471 |
+
|
| 472 |
+
- **Vulnerability Status**: [](https://snyk.io/test/github/byrizki/rusto-rs)
|
| 473 |
+
- **Reporting Vulnerabilities**: If you discover a security issue or vulnerability, please refer to our [Security Policy](SECURITY.md) for responsible disclosure steps.
|
| 474 |
+
- **Co-branding Grant**: We hereby grant [Snyk](https://snyk.io/) permission and a non-exclusive license to use, reproduce, and display the RustO! project logo and related project content on Snyk's website and marketing materials in accordance with the Snyk Open Source Program.
|
| 475 |
+
|
| 476 |
+
---
|
| 477 |
+
|
| 478 |
+
## π License
|
| 479 |
+
|
| 480 |
+
This project is licensed under the [MIT License](LICENSE).
|
| 481 |
+
|
| 482 |
+
---
|
| 483 |
+
|
| 484 |
+
## π Acknowledgments
|
| 485 |
+
|
| 486 |
+
RustO! is inspired by and builds upon the work of:
|
| 487 |
+
- **[DataLab](https://github.com/datalab-to)** β Creators of **[Indra OCR](https://github.com/datalab-to/indra-ocr)** models and the **[OmniDocBench](https://github.com/datalab-to/omnidocbench)** evaluation dataset
|
| 488 |
+
- **[RapidOCR](https://github.com/RapidAI/RapidOCR)** β Architecture and OCR pipeline reference
|
| 489 |
+
- **[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)** β Pretrained OCR models (PP-OCRv6, PP-OCRv5, PP-OCRv4)
|
| 490 |
+
- **[RTen](https://github.com/robertknight/rten)** β Pure Rust deep learning inference engine powering RustO! v0.3+
|
| 491 |
+
- **[Alibaba MNN](https://github.com/alibaba/MNN)** β High-performance inference engine that powered RustO! in version 0.2.x
|
| 492 |
+
- **[Snyk](https://snyk.io)** β Developer security and vulnerability monitoring through the Snyk Open Source Program
|
| 493 |
+
- **Rust Community** β `image`, `imageproc`, `nalgebra`, and `rayon` crates
|
| 494 |
+
|
| 495 |
+
---
|
| 496 |
+
|
| 497 |
+
## π Citation
|
| 498 |
+
|
| 499 |
+
If you use RustO! in your research or commercial application, please consider citing:
|
| 500 |
+
|
| 501 |
+
```bibtex
|
| 502 |
+
@software{rusto2024,
|
| 503 |
+
title = {RustO! - High-Performance Pure Rust OCR Library},
|
| 504 |
+
author = {Rizki & Contributors},
|
| 505 |
+
year = {2024},
|
| 506 |
+
url = {https://github.com/byrizki/rusto-rs},
|
| 507 |
+
note = {Based on RapidOCR and powered by PaddleOCR models with pure Rust RTen inference}
|
| 508 |
+
}
|
| 509 |
+
```
|