use crate::core::{errors::OCRError, traits::ImageReader};
use image::RgbImage;
use std::path::Path;
#[derive(Debug)]
pub struct DefaultImageReader {
parallel_threshold: Option<usize>,
}
impl DefaultImageReader {
pub fn new() -> Self {
Self {
parallel_threshold: None,
}
}
pub fn with_parallel_threshold(parallel_threshold: usize) -> Self {
Self {
parallel_threshold: Some(parallel_threshold),
}
}
}
impl Default for DefaultImageReader {
fn default() -> Self {
Self::new()
}
}
impl ImageReader for DefaultImageReader {
type Error = OCRError;
fn apply<P: AsRef<Path> + Send + Sync>(
&self,
imgs: impl IntoIterator<Item = P>,
) -> Result<Vec<RgbImage>, Self::Error> {
use crate::utils::load_images_batch_with_threshold;
let img_paths: Vec<_> = imgs.into_iter().collect();
load_images_batch_with_threshold(&img_paths, self.parallel_threshold)
}
}