refactor: 重构 core 包目录结构并消除旧版 mod.rs
- 优化 剥离 models,algo 层并平铺业务模块 - 重构 统一使用现代 filename.rs + 文件夹结构替代旧版 mod.rs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::loader::{ModelLoader, ModelSession, ModelType};
|
||||
use crate::loader::ModelLoader;
|
||||
use anyhow::Context;
|
||||
use ddddocr_core::error::{DdddError, Result};
|
||||
use ddddocr_core::{DetEngine, DetOutput, InferenceEngine};
|
||||
@@ -10,15 +10,6 @@ pub struct DetSession {
|
||||
pub session: RunnableModel<TypedFact, Box<dyn TypedOp>, Graph<TypedFact, Box<dyn TypedOp>>>,
|
||||
}
|
||||
|
||||
impl ModelSession for DetSession {
|
||||
fn get_model_type(&self) -> ModelType {
|
||||
todo!()
|
||||
}
|
||||
fn desc(&self) -> String {
|
||||
"Detection Model 加载成功".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl DetSession {
|
||||
pub fn new<P>(model_path: P) -> Result<Self>
|
||||
where
|
||||
|
||||
@@ -3,18 +3,6 @@ use ddddocr_core::error::Result;
|
||||
use std::io::Cursor;
|
||||
use tract_onnx::onnx;
|
||||
use tract_onnx::prelude::*; // 引入核心层的统一错误类型
|
||||
/// OCR 模型:包含路径和字符集
|
||||
|
||||
pub enum ModelType {
|
||||
Ocr,
|
||||
Det,
|
||||
Custom,
|
||||
}
|
||||
// 定义统一的 trait
|
||||
pub trait ModelSession {
|
||||
fn get_model_type(&self) -> ModelType;
|
||||
fn desc(&self) -> String;
|
||||
}
|
||||
|
||||
pub struct ModelLoader {
|
||||
pub session: RunnableModel<TypedFact, Box<dyn TypedOp>, Graph<TypedFact, Box<dyn TypedOp>>>,
|
||||
|
||||
@@ -2,8 +2,8 @@ use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use anyhow::anyhow;
|
||||
use ddddocr_core::models::ocr::metadata::Charset;
|
||||
use ddddocr_core::models::ocr::metadata::{Normalization, Resize};
|
||||
use ddddocr_core::ocr::metadata::Charset;
|
||||
use ddddocr_core::ocr::metadata::{Normalization, Resize};
|
||||
|
||||
pub const CHARSET_BETA: &[&str] = &[
|
||||
"", "笤", "谴", "膀", "荔", "佰", "电", "臁", "矍", "同", "奇", "芄", "吠", "6", "曛", "荇",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use ddddocr_core::models::det::DetectionResult;
|
||||
use ddddocr_core::det::DetectionResult;
|
||||
use ddddocr_core::{DetBuilder, Detector, ModelMetadata, Ocr, Slider}; // 假设你的包名是这个
|
||||
use ddddocr_tract::{DetSession,OcrSession};
|
||||
use image::{DynamicImage, Rgb};
|
||||
@@ -6,7 +6,7 @@ use std::fs;
|
||||
use std::path::Path;
|
||||
mod char_slice;
|
||||
use char_slice::CHARSET_BETA;
|
||||
use ddddocr_core::models::ocr::metadata::{Normalization, Resize};
|
||||
use ddddocr_core::ocr::metadata::{Normalization, Resize};
|
||||
|
||||
fn load_image<P: AsRef<Path>>(path: P) -> anyhow::Result<image::DynamicImage> {
|
||||
// 1. 先将泛型转为具体的 &Path 引用
|
||||
|
||||
Reference in New Issue
Block a user