feat: 优化 项目目录结构

This commit is contained in:
2026-05-10 20:52:42 +08:00
parent a51147c888
commit 0df9022411
14 changed files with 44 additions and 41 deletions

View File

@@ -1,14 +1,7 @@
pub mod base;
mod charset;
mod det_model;
mod image_io;
mod image_processor;
mod model;
mod model_loader;
mod ocr_model;
mod utils;
pub mod slide_model;
mod cv2;
pub mod models;
pub mod utils;
use anyhow::Result;
use image::DynamicImage;
@@ -16,9 +9,9 @@ use std::fmt::{Display, Formatter};
// 关键点:直接使用 tract 重导出的 ndarray
use crate::charset::get_default_charset;
use crate::det_model::Det;
use crate::model_loader::ModelSession;
use crate::ocr_model::Ocr;
use models::det::Det;
use models::loader::ModelSession;
use models::ocr::Ocr;
pub enum ModelSpec {
/// 默认 OCR (使用内置路径)
OcrModel,
@@ -31,7 +24,7 @@ pub enum ModelSpec {
}
impl ModelSpec {
// 将默认路径定义为内部关联常量
const DEFAULT_OCR_PATH: &'static str = "models/common_sml2h3_f32.onnx";
const DEFAULT_OCR_PATH: &'static str = "models/common.onnx";
const DEFAULT_DET_PATH: &'static str = "models/common_det.onnx";
}
pub enum Runtime {
@@ -74,7 +67,10 @@ impl DdddOcrBuilder {
/// 核心初始化逻辑
pub fn build(self) -> Result<DdddOcr> {
let runtime = match self.mode {
ModelSpec::OcrModel => Runtime::Ocr(Ocr::new(ModelSpec::DEFAULT_OCR_PATH.into(), get_default_charset())?),
ModelSpec::OcrModel => Runtime::Ocr(Ocr::new(
ModelSpec::DEFAULT_OCR_PATH.into(),
get_default_charset(),
)?),
ModelSpec::DetModel => Runtime::Det(Det::new(ModelSpec::DEFAULT_DET_PATH.into())?),
ModelSpec::CustomOcrModel { path, charset } => Runtime::Ocr(Ocr::new(path, charset)?),
};
@@ -110,7 +106,6 @@ impl DdddOcr {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_ctc_decode_indices() {
// 模拟一个 DdddOcr 实例(如果 decode 不依赖 session可以设为相关函数