refactor(slide,det): 优化项目结构,移除不必要的逻辑
- 优化 项目结构,移除不必要的逻辑
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use ddddocr_rs::models::slide::Slide;
|
||||
use ddddocr_rs::{DdddOcr, DdddOcrBuilder}; // 假设你的包名是这个
|
||||
use ddddocr_rs::{Ocr, Slider, Detector, ModelMetadata}; // 假设你的包名是这个
|
||||
use image::{DynamicImage, Rgb};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
@@ -60,23 +59,25 @@ fn save_debug_image(
|
||||
img.save(output_path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_full_classification() {
|
||||
// 1. 初始化模型
|
||||
let ocr = DdddOcrBuilder::new().build().expect("模型加载失败");
|
||||
let ocr = Ocr::new("D:\\CNWei\\CNW\\Rust\\ddddocr-rs\\models\\common_sml2h3_f32.onnx",ModelMetadata::from_builtin_beta()).expect("模型加载失败");
|
||||
|
||||
// 2. 加载测试图片
|
||||
let img = image::open("samples/code2.png").expect("测试图片不存在");
|
||||
|
||||
// 3. 执行识别
|
||||
let result = ocr.classification(&img).expect("识别过程出错");
|
||||
let result = ocr.predictor().predict(&img).expect("识别过程出错").into_text();
|
||||
|
||||
println!("识别结果: {}", result);
|
||||
assert!(!result.is_empty());
|
||||
}
|
||||
#[test]
|
||||
fn test_det_load() -> anyhow::Result<()> {
|
||||
let det = DdddOcrBuilder::new().det().build()?;
|
||||
let det = Detector::new("D:\\CNWei\\CNW\\Rust\\ddddocr-rs\\models\\common_det.onnx")?;
|
||||
let image_path = "samples/det1.png";
|
||||
let image_bytes =
|
||||
fs::read(image_path).map_err(|e| anyhow::anyhow!("无法读取图片 {}: {}", image_path, e))?;
|
||||
@@ -88,8 +89,8 @@ fn test_det_load() -> anyhow::Result<()> {
|
||||
.map_err(|e| anyhow::anyhow!("图片解码失败: {}", e))?;
|
||||
|
||||
// 【修改点 2】传入统一的 &DynamicImage 引用
|
||||
let bboxes = det.detection(&img)?;
|
||||
println!(":?{}", det);
|
||||
let bboxes = det.predict(&img)?;
|
||||
println!("{:?}", det);
|
||||
println!("检测到的目标数量: {}", bboxes.len());
|
||||
|
||||
if bboxes.is_empty() {
|
||||
@@ -111,7 +112,7 @@ fn test_det_load() -> anyhow::Result<()> {
|
||||
|
||||
#[test]
|
||||
fn test_real_slide_match() {
|
||||
let engine = Slide::new();
|
||||
let engine = Slider::new().unwrap();
|
||||
|
||||
// 1. 加载你准备好的测试图
|
||||
// 假设图片放在项目根目录下的 assets 文件夹
|
||||
@@ -142,7 +143,7 @@ fn test_real_slide_match() {
|
||||
|
||||
#[test]
|
||||
fn test_real_slide_comparison() {
|
||||
let engine = Slide::new();
|
||||
let engine = Slider::new().unwrap();
|
||||
|
||||
// 1. 加载你准备好的测试图
|
||||
// 假设图片放在项目根目录下的 assets 文件夹
|
||||
|
||||
Reference in New Issue
Block a user