refactor(ocr): 拆分字符集限制枚举并引入声明式多路组合子宏
- 将原本臃肿的 CharsetRestrict 拆分为 CharRestrict(内容过滤)和 IdRestrict(索引过滤),实现职责解耦 - 引入 any_of! 声明式宏实现无 Box、无堆内存分配的栈上多路组合,规避孤儿规则 - 完善 estimated_capacity 容量预估函数,实现真正的 O(1) 精准内存开辟
This commit is contained in:
@@ -9,7 +9,7 @@ use image::DynamicImage;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
// 关键点:直接使用 tract 重导出的 ndarray
|
||||
use crate::charset::{get_default_charset, CharsetRestrict};
|
||||
use crate::charset::{ CharRestrict};
|
||||
use crate::models::ocr::ColorRange;
|
||||
use models::det::Det;
|
||||
use models::loader::ModelSession;
|
||||
@@ -97,7 +97,7 @@ impl DdddOcr {
|
||||
pub fn classification(&self, img: &DynamicImage) -> Result<String> {
|
||||
match &self.runtime {
|
||||
// Runtime::Ocr(s) => s.predict(img).run(),
|
||||
Runtime::Ocr(s) => s.builder().charset_restrict(&CharsetRestrict::Digit).predict(img),
|
||||
Runtime::Ocr(s) => s.builder().charset_restrict(&CharRestrict::Digit).predict(img),
|
||||
Runtime::Det(_) => Err(anyhow::anyhow!("当前模型是检测模型,无法执行 OCR")),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user