refactor: 重构 ocr.rs 实现丝滑参数设置
- 重构 Ocr - 新增 OcrTask
This commit is contained in:
38
src/lib.rs
38
src/lib.rs
@@ -9,9 +9,11 @@ use std::fmt::{Display, Formatter};
|
||||
|
||||
// 关键点:直接使用 tract 重导出的 ndarray
|
||||
use crate::charset::get_default_charset;
|
||||
use crate::models::ocr::ColorRange;
|
||||
use models::det::Det;
|
||||
use models::loader::ModelSession;
|
||||
use models::ocr::Ocr;
|
||||
|
||||
pub enum ModelSpec {
|
||||
/// 默认 OCR (使用内置路径)
|
||||
OcrModel,
|
||||
@@ -24,7 +26,7 @@ pub enum ModelSpec {
|
||||
}
|
||||
impl ModelSpec {
|
||||
// 将默认路径定义为内部关联常量
|
||||
const DEFAULT_OCR_PATH: &'static str = "models/common.onnx";
|
||||
const DEFAULT_OCR_PATH: &'static str = "models/common_sml2h3_f32.onnx";
|
||||
const DEFAULT_DET_PATH: &'static str = "models/common_det.onnx";
|
||||
}
|
||||
pub enum Runtime {
|
||||
@@ -104,6 +106,40 @@ impl DdddOcr {
|
||||
}
|
||||
}
|
||||
|
||||
struct Classification {}
|
||||
#[derive(Debug)]
|
||||
struct ClassificationBuilder {
|
||||
img: DynamicImage,
|
||||
png_fix: bool,
|
||||
color_filter_colors: Option<Vec<ColorRange>>,
|
||||
color_filter_custom_ranges: Option<Vec<ColorRange>>,
|
||||
}
|
||||
impl ClassificationBuilder {
|
||||
pub fn new(img: DynamicImage) -> Self {
|
||||
ClassificationBuilder {
|
||||
img,
|
||||
png_fix: false,
|
||||
color_filter_colors: None,
|
||||
color_filter_custom_ranges: None,
|
||||
}
|
||||
}
|
||||
pub fn png_fix(mut self, value: bool) -> Self {
|
||||
self.png_fix = value;
|
||||
self
|
||||
}
|
||||
pub fn color_filter_colors(mut self, value: Vec<ColorRange>) -> Self {
|
||||
self.color_filter_colors = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn color_filter_custom_ranges(mut self, value: Vec<ColorRange>) -> Self {
|
||||
self.color_filter_custom_ranges = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> Classification {
|
||||
Classification {}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user