Files
ddddocr-rs/src/models/base.rs
2026-05-10 20:52:42 +08:00

40 lines
970 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pub trait ModelArgs {
// 获取模型路径
fn model_path(&self) -> &str;
// 获取字符集(由于 Det 没有,所以返回 Option
fn charset(&self) -> Option<&str>;
}
pub struct HasCharset {
pub charset: String,
} // 给 Ocr 和 Custom 用
pub struct NoCharset; // 给 Det 用
pub struct Model<T> {
pub path: String,
pub metadata: T,
}
// 针对有字符集的模型 (Ocr / Custom)
impl ModelArgs for Model<HasCharset> {
fn model_path(&self) -> &str {
&self.path
}
fn charset(&self) -> Option<&str> {
Some(&self.metadata.charset)
}
}
// 针对没有字符集的模型 (Det)
impl ModelArgs for Model<NoCharset> {
fn model_path(&self) -> &str {
&self.path
}
fn charset(&self) -> Option<&str> {
None
}
}
pub type OcrModel = Model<HasCharset>;
pub type DetModel = Model<NoCharset>;
pub type CustomModel = Model<HasCharset>; // Ocr 和 Custom 逻辑一致,可以复用