use image::DynamicImage;
#[derive(Debug, Clone, bon::Builder)]
#[non_exhaustive]
pub struct OcrPageResult {
pub page_index: u32,
pub text: String,
}
impl OcrPageResult {
#[inline]
pub fn has_text(&self) -> bool {
!self.text.is_empty()
}
}
#[derive(Debug, Clone, bon::Builder)]
#[non_exhaustive]
pub struct OcrConfig {
#[builder(default = 0.7)]
pub confidence_threshold: f32,
}
impl Default for OcrConfig {
fn default() -> Self {
Self::builder().build()
}
}
pub trait OcrBackend: Send + Sync {
fn run(
&self,
image: &DynamicImage,
page_index: u32,
config: &OcrConfig,
) -> Result<OcrPageResult, Box<dyn std::error::Error + Send + Sync>>;
}