Overview
RettoSession<W: RettoWorker> is the primary interface for executing OCR operations in Retto. It manages the complete OCR pipeline including text detection, classification, and recognition.
Type Definition
RettoWorker type, which handles the actual model inference. Common implementations include RettoOrtWorker for ONNX Runtime.
Constructor
new()
Creates a new OCR session with the specified configuration.Configuration for the session, including worker config and processor settings
Returns a new session instance or an error if initialization fails (e.g., model loading errors)
Example
Methods
run()
Executes the complete OCR pipeline on an input image and returns all results.Raw image data in any format supported by the
image crate (PNG, JPEG, etc.)Combined results from all three stages: detection, classification, and recognition
Processing Pipeline
Therun() method executes three sequential stages:
- Detection: Locates text regions in the image
- Classification: Determines text orientation (0° or 180°)
- Recognition: Extracts text content from each region
Example
run_stream()
Executes the OCR pipeline with streaming results via a channel.Raw image data in any format supported by the
image crateChannel sender for receiving stage results as they complete
Returns Ok(()) if pipeline completes successfully. Results are sent via the channel.
Use Case
The streaming API is useful when you need to:- Process results as soon as each stage completes
- Display progressive results in a UI
- Implement early termination based on intermediate results
Example
Image Processing
Before OCR processing begins,RettoSession automatically:
- Decodes the input image from raw bytes
- Resizes the image based on
max_side_lenandmin_side_lenconstraints - Maintains aspect ratio during resizing
- Scales coordinates back to original image dimensions in results
RettoSessionConfig.
Thread Safety
RettoSession is not Send or Sync by default. For multi-threaded usage:
- Create one session per thread
- Use a thread pool pattern with session-per-worker
- Share configuration but not session instances
Related Types
RettoSessionConfig- Session configurationRettoWorkerResult- Complete OCR resultsRettoWorkerStageResult- Individual stage results
