oar_ocr/core/inference/
image_reader.rs1use crate::core::{errors::OCRError, traits::ImageReader};
4use image::RgbImage;
5use std::path::Path;
6
7#[derive(Debug)]
9pub struct DefaultImageReader {
10 parallel_threshold: Option<usize>,
12}
13
14impl DefaultImageReader {
15 pub fn new() -> Self {
17 Self {
18 parallel_threshold: None,
19 }
20 }
21
22 pub fn with_parallel_threshold(parallel_threshold: usize) -> Self {
24 Self {
25 parallel_threshold: Some(parallel_threshold),
26 }
27 }
28}
29
30impl Default for DefaultImageReader {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36impl ImageReader for DefaultImageReader {
37 type Error = OCRError;
38
39 fn apply<P: AsRef<Path> + Send + Sync>(
40 &self,
41 imgs: impl IntoIterator<Item = P>,
42 ) -> Result<Vec<RgbImage>, Self::Error> {
43 use crate::utils::load_images_batch_with_threshold;
44
45 let img_paths: Vec<_> = imgs.into_iter().collect();
46 load_images_batch_with_threshold(&img_paths, self.parallel_threshold)
47 }
48}