oar_ocr/core/batch/dynamic/
config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub enum ShapeCompatibilityStrategy {
8 Exact,
10 AspectRatio {
12 tolerance: f32,
14 },
15 MaxDimension {
17 bucket_size: u32,
19 },
20 Custom {
22 targets: Vec<(u32, u32)>,
24 tolerance: f32,
26 },
27}
28
29impl Default for ShapeCompatibilityStrategy {
30 fn default() -> Self {
31 Self::AspectRatio { tolerance: 0.1 }
32 }
33}
34
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
37pub enum PaddingStrategy {
38 Zero,
40 Center {
42 fill_color: [u8; 3],
44 },
45 Edge,
47 Smart,
49}
50
51impl Default for PaddingStrategy {
52 fn default() -> Self {
53 Self::Center {
54 fill_color: [0, 0, 0],
55 }
56 }
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct DynamicBatchConfig {
62 pub max_detection_batch_size: usize,
64 pub max_recognition_batch_size: usize,
66 pub min_batch_size: usize,
68 pub shape_compatibility: ShapeCompatibilityStrategy,
70 pub padding_strategy: PaddingStrategy,
72}
73
74impl Default for DynamicBatchConfig {
75 fn default() -> Self {
76 Self {
77 max_detection_batch_size: 8,
78 max_recognition_batch_size: 16,
79 min_batch_size: 2,
80 shape_compatibility: ShapeCompatibilityStrategy::default(),
81 padding_strategy: PaddingStrategy::default(),
82 }
83 }
84}
85
86impl DynamicBatchConfig {
87 pub fn new() -> Self {
89 Self::default()
90 }
91
92 pub fn with_max_detection_batch_size(mut self, size: usize) -> Self {
94 self.max_detection_batch_size = size;
95 self
96 }
97
98 pub fn with_max_recognition_batch_size(mut self, size: usize) -> Self {
100 self.max_recognition_batch_size = size;
101 self
102 }
103
104 pub fn with_min_batch_size(mut self, size: usize) -> Self {
106 self.min_batch_size = size;
107 self
108 }
109
110 pub fn with_shape_compatibility(mut self, strategy: ShapeCompatibilityStrategy) -> Self {
112 self.shape_compatibility = strategy;
113 self
114 }
115
116 pub fn with_padding_strategy(mut self, strategy: PaddingStrategy) -> Self {
118 self.padding_strategy = strategy;
119 self
120 }
121}