准备 - core:内置官方字符集(OLD/BETA)与 ModelMetadata::from_builtin_* 构造器 - ort:导出 Session、实现 Info、修正 cuda feature 接线、共享推理工具 - tract2:包名更名(原 ddddocr-tract 已被占用)并完成规范整改 - 集成测试按领域拆分(ocr / det / slide / common / api_surface) - 发布准备:Cargo.toml 元数据、workspace 版本 0.2.4、LICENSE/ NOTICE、README 模型下载说明
57 lines
1.8 KiB
Rust
57 lines
1.8 KiB
Rust
//! OCR 识别与模型信息集成测试。
|
|
|
|
mod common;
|
|
|
|
use common::{model_path, sample_path};
|
|
use ddddocr_core::traits::{Info, Loader};
|
|
use ddddocr_core::{ModelMetadata, Normalization, Ocr, Resize};
|
|
use ddddocr_ort::OcrRuntime;
|
|
use ddddocr_ort::loader::ModelLoader;
|
|
|
|
/// 用官方 sml2h3 f32 模型识别验证码图片,结果不应为空。
|
|
#[test]
|
|
fn ocr_classification_recognizes_code_image() {
|
|
let session = ModelLoader::default()
|
|
.use_gpu(false)
|
|
.build_for_path(model_path("common_sml2h3_f32.onnx"))
|
|
.expect("模型加载失败");
|
|
let metadata = ModelMetadata::from_builtin_beta(
|
|
false,
|
|
Resize::DynamicWidth(64),
|
|
1,
|
|
Normalization::MinusOneToOne,
|
|
);
|
|
let ocr = OcrRuntime::new(session, metadata);
|
|
|
|
let img = image::open(sample_path("code2.png")).expect("测试图片不存在");
|
|
let text = Ocr::builder()
|
|
.build_with(&ocr)
|
|
.predict(&img)
|
|
.expect("识别过程出错")
|
|
.into_text();
|
|
|
|
println!("识别结果: {text}");
|
|
assert!(!text.is_empty(), "识别结果不应为空");
|
|
}
|
|
|
|
/// 真实模型应能通过 `Info` trait 返回输入/输出张量信息。
|
|
#[test]
|
|
fn model_info_lists_inputs_and_outputs() -> anyhow::Result<()> {
|
|
let session = ModelLoader::default()
|
|
.build_for_path(model_path("common_huashi666_i64.onnx"))
|
|
.expect("建立测试模型图失败");
|
|
let metadata = ModelMetadata::from_builtin_beta(
|
|
false,
|
|
Resize::DynamicWidth(64),
|
|
1,
|
|
Normalization::MinusOneToOne,
|
|
);
|
|
let ocr = OcrRuntime::new(session, metadata);
|
|
|
|
let inputs = ocr.input_info()?;
|
|
let outputs = ocr.output_info()?;
|
|
assert!(!inputs.is_empty(), "模型应有输入张量信息");
|
|
assert!(!outputs.is_empty(), "模型应有输出张量信息");
|
|
Ok(())
|
|
}
|