docs(core): 精简 lib/types/error 文档注释并新增快速开始示例

This commit is contained in:
2026-08-05 09:43:46 +08:00
parent a3c4614574
commit 84cc97b201
11 changed files with 60 additions and 196 deletions

View File

@@ -105,7 +105,7 @@ fn save_rust_result(result: &ImageBuffer<Luma<f32>, Vec<f32>>, filename: &str) {
}
#[test]
fn test_full_classification() {
let model = OrtModelLoader::default().use_gpu(false)
let session = OrtModelLoader::default().use_gpu(false)
.build_for_path("D:\\CNWei\\CNW\\Rust\\ddddocr-rs\\models\\common_sml2h3_f32.onnx")
// .build_for_path("D:\\CNWei\\CNW\\Rust\\ddddocr-rs\\models\\common_old.onnx")
.expect("模型加载失败");
@@ -117,7 +117,7 @@ fn test_full_classification() {
Normalization::MinusOneToOne,
);
// 1. 初始化模型
let ocr = OcrRuntime::new(model, metadata);
let ocr = OcrRuntime::new(session, metadata);
// 2. 加载测试图片
let img =
image::open("D:/CNWei/CNW/Rust/ddddocr-rs/samples/code2.png").expect("测试图片不存在");
@@ -132,7 +132,7 @@ fn test_full_classification() {
// .predict(&img)
// .expect("识别过程出错")
// .into_text();
let res=Ocr::builder().runner(&ocr).predict(&img).expect("s").into_text();
let res=Ocr::builder().build_with(&ocr).predict(&img).expect("s").into_text();
// println!("识别结果: {}", result);
println!("识别结果: {}", res);
@@ -141,10 +141,10 @@ fn test_full_classification() {
}
#[test]
fn test_det_load() -> anyhow::Result<()> {
let det_model = OrtModelLoader::default()
let session = OrtModelLoader::default()
.build_for_path("D:\\CNWei\\CNW\\Rust\\ddddocr-rs\\models\\common_det.onnx")
.expect("模型加载失败");
let det = DetRuntime::new(det_model);
let det = DetRuntime::new(session);
let image_path = "D:/CNWei/CNW/Rust/ddddocr-rs/samples/det1.png";
let image_bytes =
fs::read(image_path).map_err(|e| anyhow::anyhow!("无法读取图片 {}: {}", image_path, e))?;