oar_ocr/pipeline/stages/mod.rs
1//! Shared stage processors for the OCR pipeline.
2//!
3//! This module provides reusable stage processors that eliminate code duplication
4//! across different pipeline flows (single-image, in-memory, dynamic batching,
5//! detection-from-memory). Each processor encapsulates the logic for a specific
6//! pipeline stage with consistent error handling, logging, and performance characteristics.
7//!
8//! # Extensible Pipeline Architecture
9//!
10//! The pipeline supports extensible stages through the `PipelineStage` trait and
11//! `StageRegistry` system, allowing new stages to be added without modifying core
12//! pipeline code.
13//!
14//! # Stage Processor Pattern Abstraction
15//!
16//! This module includes helper utilities that reduce code duplication across
17//! stage processors by abstracting common lifecycle patterns:
18//!
19//! - **Timing management** - Automatic start/stop timing for operations
20//! - **Empty input handling** - Consistent behavior for empty input collections
21//! - **Parallel processing** - Automatic decisions between sequential and parallel processing
22//! - **Metrics collection** - Standardized success/failure counting and metadata
23//! - **Result wrapping** - Consistent `StageResult` creation with metrics
24//!
25//! These abstractions reduce repetitive code by approximately 25-35% across
26//! the orientation, cropping, and recognition processors while maintaining
27//! the same functionality and API compatibility.
28//!
29//! See [`processor_helper`] for the concrete helper implementations.
30
31pub mod config;
32mod cropping;
33mod extensible;
34mod orientation;
35mod processor_helper;
36mod recognition;
37mod registry;
38mod text_detection;
39mod types;
40
41// Re-export public types and processors
42pub use cropping::{
43 CroppingConfig, CroppingResult, CroppingStageProcessor, ExtensibleCroppingStage,
44};
45pub use orientation::{
46 ExtensibleOrientationStage, OrientationConfig, OrientationResult, OrientationStageProcessor,
47};
48pub use processor_helper::{
49 BatchConfig, BatchProcessor, SingleItemProcessor, StageAlgorithm, process_items,
50 run_with_metrics, run_with_metrics_and_fallback,
51};
52pub use recognition::{
53 ExtensibleRecognitionStage, GroupingStrategy, GroupingStrategyConfig, GroupingStrategyFactory,
54 OrientationCorrectionConfig, OrientationCorrector, RecognitionConfig, RecognitionResult,
55 RecognitionStageProcessor,
56};
57pub use types::{StageMetrics, StageProcessor, StageProcessorHelper, StageResult};
58
59// Re-export extensible pipeline components
60pub use config::{ExtensiblePipelineConfig, GlobalPipelineSettings};
61pub use extensible::{PipelineStage, StageContext, StageData, StageDependency, StageId};
62pub use registry::{ExtensiblePipeline, PipelineExecutor};
63
64// Re-export example stages
65pub use text_detection::{
66 ExtensibleTextDetectionStage, ExtensibleTextLineOrientationStage, TextDetectionConfig,
67 TextDetectionResult, TextLineOrientationConfig,
68};