- 源码 316 文件收编为 rusto-rs/ 文件夹,随本仓库管理 - 移除内部 .git(补丁已存档 docs/rusto-rs-metal-patch-20260912.patch,上游可随时 re-clone) - target/ 与 docs/.yarn 缓存不入库;本地改动:ROCR_* 环境变量调优 + Metal 链接修复 + 预处理测试脚本
173 lines
4.8 KiB
Markdown
173 lines
4.8 KiB
Markdown
---
|
|
title: 'InitializeConfig'
|
|
description: 'Public initialization API reference for model presets, model paths, and auxiliary stages.'
|
|
navigation:
|
|
icon: 'i-ph-code-block'
|
|
seo:
|
|
title: 'InitializeConfig - RustO! API Reference'
|
|
description: 'Public initialization API reference for model presets, model paths, and auxiliary stages.'
|
|
---
|
|
|
|
`InitializeConfig` configures model files, vocabulary dictionaries, and auxiliary networks to instantiate a reusable OCR engine session.
|
|
|
|
## Architecture Contract
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
subgraph Config ["InitializeConfig (Model & Session Setup)"]
|
|
P["Model Preset (ppv6, ppv5, ppv4, ppv3)"]
|
|
D["Detection Model Path (det.mnn)"]
|
|
R["Recognition Model Path (rec.mnn)"]
|
|
V["Vocabulary Dictionary (dict.txt)"]
|
|
C["Optional CLS Classifier (cls.mnn)"]
|
|
O["Optional Page Orientation (orient.mnn)"]
|
|
end
|
|
|
|
Config -->|"RustO::initialize(config)"| Engine["RustO Engine Instance<br/>(Reusable Inference Session)"]
|
|
```
|
|
|
|
---
|
|
|
|
## Canonical Wire Schema
|
|
|
|
For C FFI, JNI, and standalone binding JSON serialization:
|
|
|
|
```json
|
|
{
|
|
"template": "ppv6",
|
|
"detection": {
|
|
"modelPath": "models/det.mnn",
|
|
"thresh": 0.3,
|
|
"boxThresh": 0.6,
|
|
"unclipRatio": 2.0,
|
|
"limitSideLen": 736,
|
|
"limitType": "min",
|
|
"useDilation": true
|
|
},
|
|
"recognition": {
|
|
"modelPath": "models/rec.mnn",
|
|
"dictPath": "models/dict.txt"
|
|
},
|
|
"classification": {
|
|
"enabled": true,
|
|
"modelPath": "models/cls.mnn",
|
|
"thresh": 0.9
|
|
},
|
|
"orientation": {
|
|
"enabled": true,
|
|
"modelPath": "models/orient.mnn",
|
|
"thresh": 0.85
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Presets Reference
|
|
|
|
| Preset | Default Detector Resize | Default Resize Mode | Default Unclip Ratio | Compatible Architecture |
|
|
| ---------------- | ----------------------- | ------------------- | -------------------- | ------------------------------ |
|
|
| `ppv6` (Default) | `736` | `min` | `2.0` | PP-OCRv6 (Tiny, Small, Medium) |
|
|
| `ppv5` | `736` | `min` | `2.0` | PP-OCRv5 (Mobile, Server) |
|
|
| `ppv4` | `960` | `max` | `1.5` | PP-OCRv4 (Mobile, Server) |
|
|
| `ppv3` | `960` | `max` | `1.5` | PP-OCRv3 |
|
|
|
|
---
|
|
|
|
## Public API Across All Bindings
|
|
|
|
### Rust
|
|
|
|
```rust
|
|
use rusto::{InitializeConfig, RustO};
|
|
|
|
// Method 1: Constructor with default PP-OCRv6 preset
|
|
let config = InitializeConfig::ppv6("det.mnn", "rec.mnn", "dict.txt")
|
|
.with_det_thresh(0.3)
|
|
.with_det_box_thresh(0.6)
|
|
.with_unclip_ratio(2.0)
|
|
.with_use_dilation(true)
|
|
.with_cls_threshold("cls.mnn", 0.9)
|
|
.with_orientation_threshold("orient.mnn", 0.85);
|
|
|
|
let mut ocr = RustO::initialize(config)?;
|
|
```
|
|
|
|
### .NET / C#
|
|
|
|
```csharp
|
|
using RustODotnet;
|
|
|
|
var config = new InitializeConfig
|
|
{
|
|
Template = "ppv6",
|
|
Detection = new DetectionConfig { ModelPath = "det.mnn" },
|
|
Recognition = new RecognitionConfig { ModelPath = "rec.mnn", DictPath = "dict.txt" },
|
|
Classification = new ClassificationConfig { Enabled = true, ModelPath = "cls.mnn", Thresh = 0.9f },
|
|
Orientation = new OrientationConfig { Enabled = true, ModelPath = "orient.mnn", Thresh = 0.85f }
|
|
};
|
|
|
|
using var ocr = RustO.Initialize(config);
|
|
```
|
|
|
|
### iOS (Swift)
|
|
|
|
```swift
|
|
import RustO
|
|
|
|
let config = InitializeConfig(
|
|
template: "ppv6",
|
|
detection: DetectionConfig(modelPath: "det.mnn"),
|
|
recognition: RecognitionConfig(modelPath: "rec.mnn", dictPath: "dict.txt"),
|
|
classification: ClassificationConfig(enabled: true, modelPath: "cls.mnn", thresh: 0.9),
|
|
orientation: OrientationConfig(enabled: true, modelPath: "orient.mnn", thresh: 0.85)
|
|
)
|
|
|
|
let ocr = try RustO.initialize(config: config)
|
|
```
|
|
|
|
### Android (Kotlin)
|
|
|
|
```kotlin
|
|
import com.byrizki.rusto.*
|
|
|
|
val config = InitializeConfig(
|
|
template = "ppv6",
|
|
detection = DetectionConfig(modelPath = "det.mnn"),
|
|
recognition = RecognitionConfig(modelPath = "rec.mnn", dictPath = "dict.txt"),
|
|
classification = ClassificationConfig(enabled = true, modelPath = "cls.mnn", thresh = 0.9f),
|
|
orientation = OrientationConfig(enabled = true, modelPath = "orient.mnn", thresh = 0.85f)
|
|
)
|
|
|
|
val ocr = RustO.initialize(context, config)
|
|
```
|
|
|
|
### React Native
|
|
|
|
```typescript
|
|
import { initialize } from 'react-native-rusto';
|
|
|
|
await initialize({
|
|
preset: 'ppv6',
|
|
models: {
|
|
detection: 'det.mnn',
|
|
recognition: 'rec.mnn',
|
|
dictionary: 'dict.txt',
|
|
classification: 'cls.mnn',
|
|
orientation: 'orient.mnn',
|
|
},
|
|
});
|
|
```
|
|
|
|
### C FFI
|
|
|
|
```c
|
|
#include "librusto.h"
|
|
|
|
const char *config_json = "{\"template\":\"ppv6\",\"detection\":{\"modelPath\":\"det.mnn\"},\"recognition\":{\"modelPath\":\"rec.mnn\",\"dictPath\":\"dict.txt\"}}";
|
|
ROCRHandle *handle = rocr_initialize(config_json);
|
|
|
|
// Later:
|
|
rocr_free(handle);
|
|
```
|