refactor: 抽象解耦推理引擎并重构为多Crate工作空间架构
- 移除 核心层与 tract/Tensor 的强耦合,前/后处理全线转用标准 ndarray - 针对 OCR 与目标检测(Det)分别设计独立的强类型输出小枚举(OcrOutput/DetOutput) - 利用 Trait 关联类型(Associated Type)InferenceEngine,OcrEngine,DetEngine 统一接口,实现多后端解耦 - 引入 thiserror 库,建立完备的强类型错误处理机制(DdddError/Result) - 完成项目结构初拆,剥离为 ddddocr-core 和 ddddocr-tract
This commit is contained in:
40
ddddocr-core/src/utils/image_processor.rs
Normal file
40
ddddocr-core/src/utils/image_processor.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use image::{DynamicImage, GrayImage, imageops::FilterType, Rgb, ImageBuffer};
|
||||
use anyhow::{anyhow, Result};
|
||||
use crate::models::ocr::color_filter::HsvRange;
|
||||
use crate::utils::image_proc::rgb_to_opencv_hsv;
|
||||
|
||||
/// 对应 Python 的 convert_to_grayscale
|
||||
/// 将图像转换为灰度图 (L模式)
|
||||
pub fn convert_to_grayscale(image: &DynamicImage) -> GrayImage {
|
||||
// Rust utils 库的 to_luma8 会根据标准的亮度公式进行转换
|
||||
image.to_luma8()
|
||||
}
|
||||
|
||||
/// 对应 Python 的 resize_image
|
||||
/// 调整图像尺寸。当前版本仅实现 keep_aspect_ratio=false
|
||||
pub fn resize_image(
|
||||
image: &DynamicImage,
|
||||
target_width: u32,
|
||||
target_height: u32,
|
||||
// resample 参数我们直接使用 FilterType,Lanczos3 是最接近 Python LANCZOS 的
|
||||
) -> DynamicImage {
|
||||
|
||||
// image::imageops::resize 的最高层封装
|
||||
// FilterType::Lanczos3 与 Python Pillow 的 Image.LANCZOS 算法完全对齐,缩放质量最高
|
||||
image.resize_exact(target_width, target_height, FilterType::Lanczos3)
|
||||
}
|
||||
// pub fn resize_image(
|
||||
// image: &GrayImage,
|
||||
// target_width: u32,
|
||||
// target_height: u32,
|
||||
// // resample 参数我们直接使用 FilterType,Lanczos3 是最接近 Python LANCZOS 的
|
||||
// ) -> GrayImage {
|
||||
// // 使用 resize 算法进行精确缩放
|
||||
// image::imageops::resize(
|
||||
// image,
|
||||
// target_width,
|
||||
// target_height,
|
||||
// FilterType::Lanczos3
|
||||
// )
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user