- 源码 316 文件收编为 rusto-rs/ 文件夹,随本仓库管理 - 移除内部 .git(补丁已存档 docs/rusto-rs-metal-patch-20260912.patch,上游可随时 re-clone) - target/ 与 docs/.yarn 缓存不入库;本地改动:ROCR_* 环境变量调优 + Metal 链接修复 + 预处理测试脚本
29 lines
960 B
Rust
29 lines
960 B
Rust
/// OCR example with prepared orientation and classification models.
|
|
use rusto::{DetectTextResult, ImageSource, InitializeConfig, OcrRunOptions, RustO};
|
|
use std::error::Error;
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
let config = InitializeConfig::ppv5(
|
|
"models/PPOCR_v5/det.mnn",
|
|
"models/PPOCR_v5/rec.mnn",
|
|
"models/PPOCR_v5/dict.txt",
|
|
)
|
|
.with_cls("models/PPOCR_v5/lcnet-text.mnn")
|
|
.with_orientation("models/PPOCR_v5/lcnet.mnn");
|
|
let mut ocr = RustO::initialize(config)?;
|
|
let result = ocr.detect_text(
|
|
&ImageSource::Path("models/test_images/example1.png".into()),
|
|
&OcrRunOptions {
|
|
classification: Some(true),
|
|
orientation: Some(true),
|
|
..Default::default()
|
|
},
|
|
)?;
|
|
if let DetectTextResult::Structured(results) = result {
|
|
for result in results {
|
|
println!("{} ({:.3})", result.text, result.score);
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|