pub struct OAROCRBuilder { /* private fields */ }Expand description
Builder for creating OAROCR instances.
This struct provides a fluent API for configuring and building OAROCR pipeline instances with various options.
Implementations§
Source§impl OAROCRBuilder
impl OAROCRBuilder
Sourcepub fn new(
text_detection_model_path: String,
text_recognition_model_path: String,
text_rec_character_dict_path: String,
) -> Self
pub fn new( text_detection_model_path: String, text_recognition_model_path: String, text_rec_character_dict_path: String, ) -> Self
Creates a new OAROCRBuilder with the required parameters.
§Arguments
text_detection_model_path- Path to the text detection model filetext_recognition_model_path- Path to the text recognition model filetext_rec_character_dict_path- Path to the character dictionary file
§Returns
A new OAROCRBuilder instance
Sourcepub fn from_config(config: OAROCRConfig) -> Self
pub fn from_config(config: OAROCRConfig) -> Self
Sourcepub fn doc_orientation_classify_model_name(self, name: String) -> Self
pub fn doc_orientation_classify_model_name(self, name: String) -> Self
Sourcepub fn doc_orientation_classify_model_path(
self,
path: impl Into<PathBuf>,
) -> Self
pub fn doc_orientation_classify_model_path( self, path: impl Into<PathBuf>, ) -> Self
Sourcepub fn doc_orientation_threshold(self, threshold: f32) -> Self
pub fn doc_orientation_threshold(self, threshold: f32) -> Self
Sets the document orientation confidence threshold.
Specifies the minimum confidence score required for orientation predictions. If the confidence is below this threshold, the orientation may be treated as uncertain and fall back to default behavior.
§Arguments
threshold- Minimum confidence threshold (0.0 to 1.0)
§Returns
The updated builder instance Sets the confidence threshold for document orientation classification.
This threshold determines the minimum confidence required for orientation predictions. If the confidence is below this threshold, the orientation may be treated as uncertain and fall back to default behavior.
§Arguments
threshold- Minimum confidence threshold (0.0 to 1.0)
§Returns
The updated builder instance
Sourcepub fn doc_unwarping_model_name(self, name: String) -> Self
pub fn doc_unwarping_model_name(self, name: String) -> Self
Sourcepub fn doc_unwarping_model_path(self, path: impl Into<PathBuf>) -> Self
pub fn doc_unwarping_model_path(self, path: impl Into<PathBuf>) -> Self
Sourcepub fn text_detection_model_name(self, name: String) -> Self
pub fn text_detection_model_name(self, name: String) -> Self
Sourcepub fn text_detection_model_path(self, path: impl Into<PathBuf>) -> Self
pub fn text_detection_model_path(self, path: impl Into<PathBuf>) -> Self
Sourcepub fn text_detection_batch_size(self, batch_size: usize) -> Self
pub fn text_detection_batch_size(self, batch_size: usize) -> Self
Sourcepub fn text_recognition_model_name(self, name: String) -> Self
pub fn text_recognition_model_name(self, name: String) -> Self
Sourcepub fn text_recognition_model_path(self, path: impl Into<PathBuf>) -> Self
pub fn text_recognition_model_path(self, path: impl Into<PathBuf>) -> Self
Sourcepub fn text_recognition_batch_size(self, batch_size: usize) -> Self
pub fn text_recognition_batch_size(self, batch_size: usize) -> Self
Sourcepub fn textline_orientation_classify_model_name(self, name: String) -> Self
pub fn textline_orientation_classify_model_name(self, name: String) -> Self
Sourcepub fn textline_orientation_classify_model_path(
self,
path: impl Into<PathBuf>,
) -> Self
pub fn textline_orientation_classify_model_path( self, path: impl Into<PathBuf>, ) -> Self
Sourcepub fn textline_orientation_classify_batch_size(self, batch_size: usize) -> Self
pub fn textline_orientation_classify_batch_size(self, batch_size: usize) -> Self
Sourcepub fn textline_orientation_input_shape(self, shape: (u32, u32)) -> Self
pub fn textline_orientation_input_shape(self, shape: (u32, u32)) -> Self
Sourcepub fn textline_orientation_threshold(self, threshold: f32) -> Self
pub fn textline_orientation_threshold(self, threshold: f32) -> Self
Sets the text line orientation confidence threshold.
Specifies the minimum confidence score required for text line orientation predictions. If the confidence is below this threshold, the orientation may be treated as uncertain and fall back to default behavior.
§Arguments
threshold- Minimum confidence threshold (0.0 to 1.0)
§Returns
The updated builder instance
Sets the text line orientation confidence threshold.
Specifies the minimum confidence score required for text line orientation predictions. If the confidence is below this threshold, the orientation may be treated as uncertain and fall back to default behavior.
§Arguments
threshold- Minimum confidence threshold (0.0 to 1.0)
§Returns
The updated builder instance
Sourcepub fn use_doc_orientation_classify(self, use_it: bool) -> Self
pub fn use_doc_orientation_classify(self, use_it: bool) -> Self
Sourcepub fn use_doc_unwarping(self, use_it: bool) -> Self
pub fn use_doc_unwarping(self, use_it: bool) -> Self
Sourcepub fn use_textline_orientation(self, use_it: bool) -> Self
pub fn use_textline_orientation(self, use_it: bool) -> Self
Sourcepub fn parallel_policy(self, policy: ParallelPolicy) -> Self
pub fn parallel_policy(self, policy: ParallelPolicy) -> Self
Sourcepub fn text_detection_ort_session(self, config: OrtSessionConfig) -> Self
pub fn text_detection_ort_session(self, config: OrtSessionConfig) -> Self
Sourcepub fn text_recognition_ort_session(self, config: OrtSessionConfig) -> Self
pub fn text_recognition_ort_session(self, config: OrtSessionConfig) -> Self
Sourcepub fn textline_orientation_ort_session(self, config: OrtSessionConfig) -> Self
pub fn textline_orientation_ort_session(self, config: OrtSessionConfig) -> Self
Sourcepub fn global_ort_session(self, config: OrtSessionConfig) -> Self
pub fn global_ort_session(self, config: OrtSessionConfig) -> Self
Sets the ONNX Runtime session configuration for all components.
This is a convenience method that applies the same ONNX session configuration to text detection, text recognition, and text line orientation classification.
§Arguments
config- The ONNX Runtime session configuration
§Returns
The updated builder instance
Sourcepub fn with_high_performance(self) -> Self
pub fn with_high_performance(self) -> Self
Convenience method to enable high-performance processing configuration.
This applies optimizations for batch processing:
- Increases parallel processing thresholds
- Optimizes memory usage
- Configures efficient batching strategies
§Returns
The updated builder instance
§Example
use oar_ocr::pipeline::OAROCRBuilder;
let builder = OAROCRBuilder::new(
"detection.onnx".to_string(),
"recognition.onnx".to_string(),
"dict.txt".to_string()
)
.with_high_performance(); // Optimize for batch processingSourcepub fn with_low_resource(self) -> Self
pub fn with_low_resource(self) -> Self
Convenience method for mobile/resource-constrained environments.
This configures the pipeline for minimal resource usage:
- Reduces parallel processing to avoid overwhelming the system
- Uses conservative memory settings
- Prioritizes stability over speed
§Returns
The updated builder instance
§Example
use oar_ocr::pipeline::OAROCRBuilder;
let builder = OAROCRBuilder::new(
"detection.onnx".to_string(),
"recognition.onnx".to_string(),
"dict.txt".to_string()
)
.with_low_resource(); // Optimize for limited resourcesSourcepub fn text_detection_session_pool_size(self, size: usize) -> Self
pub fn text_detection_session_pool_size(self, size: usize) -> Self
Sourcepub fn text_recognition_session_pool_size(self, size: usize) -> Self
pub fn text_recognition_session_pool_size(self, size: usize) -> Self
Sourcepub fn textline_orientation_session_pool_size(self, size: usize) -> Self
pub fn textline_orientation_session_pool_size(self, size: usize) -> Self
Sourcepub fn global_session_pool_size(self, size: usize) -> Self
pub fn global_session_pool_size(self, size: usize) -> Self
Sourcepub fn text_det_limit_side_len(self, limit: u32) -> Self
pub fn text_det_limit_side_len(self, limit: u32) -> Self
Sourcepub fn text_det_limit_type(self, limit_type: LimitType) -> Self
pub fn text_det_limit_type(self, limit_type: LimitType) -> Self
Sourcepub fn text_det_input_shape(self, shape: (u32, u32, u32)) -> Self
pub fn text_det_input_shape(self, shape: (u32, u32, u32)) -> Self
Sourcepub fn text_det_max_side_limit(self, max_side_limit: u32) -> Self
pub fn text_det_max_side_limit(self, max_side_limit: u32) -> Self
Sets the text detection maximum side limit.
This controls the maximum allowed size for any side of an image during text detection preprocessing. Images larger than this limit will be resized to fit within the constraint while maintaining aspect ratio.
§Arguments
max_side_limit- The maximum side limit for image processing (default: 4000)
§Returns
The updated builder instance
§Example
use oar_ocr::pipeline::OAROCRBuilder;
let builder = OAROCRBuilder::new(
"detection_model.onnx".to_string(),
"recognition_model.onnx".to_string(),
"char_dict.txt".to_string()
)
.text_det_max_side_limit(5000); // Allow larger imagesSourcepub fn text_det_threshold(self, threshold: f32) -> Self
pub fn text_det_threshold(self, threshold: f32) -> Self
Sets the text detection binarization threshold.
This controls the threshold used for binarizing the detection output. Lower values may detect more text but with more false positives.
§Arguments
thresh- The binarization threshold (default: 0.3)
§Returns
The updated builder instance
§Example
use oar_ocr::pipeline::OAROCRBuilder;
let builder = OAROCRBuilder::new(
"detection_model.onnx".to_string(),
"recognition_model.onnx".to_string(),
"char_dict.txt".to_string()
)
.text_det_threshold(0.4); // Higher threshold for more precise detectionSets the text detection binarization threshold.
This controls the threshold used for binarizing the detection output. Lower values may detect more text but with more false positives.
§Arguments
threshold- The binarization threshold (default: 0.3)
§Returns
The updated builder instance
Sourcepub fn text_det_box_threshold(self, threshold: f32) -> Self
pub fn text_det_box_threshold(self, threshold: f32) -> Self
Sets the text detection box score threshold.
This controls the threshold for filtering text boxes based on their confidence scores. Higher values will filter out more uncertain detections.
§Arguments
box_thresh- The box score threshold (default: 0.6)
§Returns
The updated builder instance
§Example
use oar_ocr::pipeline::OAROCRBuilder;
let builder = OAROCRBuilder::new(
"detection_model.onnx".to_string(),
"recognition_model.onnx".to_string(),
"char_dict.txt".to_string()
)
.text_det_box_threshold(0.7); // Higher threshold for more confident boxesSets the text detection box score threshold.
This controls the threshold for filtering text boxes based on their confidence scores. Higher values will filter out more uncertain detections.
§Arguments
threshold- The box score threshold (default: 0.6)
§Returns
The updated builder instance
Sourcepub fn text_det_unclip_ratio(self, unclip_ratio: f32) -> Self
pub fn text_det_unclip_ratio(self, unclip_ratio: f32) -> Self
Sets the text detection unclip ratio.
This controls how much to expand detected text boxes. Higher values will expand boxes more, potentially capturing more complete text.
§Arguments
unclip_ratio- The unclip ratio for expanding text boxes (default: 1.5)
§Returns
The updated builder instance
§Example
use oar_ocr::pipeline::OAROCRBuilder;
let builder = OAROCRBuilder::new(
"detection_model.onnx".to_string(),
"recognition_model.onnx".to_string(),
"char_dict.txt".to_string()
)
.text_det_unclip_ratio(2.0); // More expansion for better text captureSourcepub fn text_rec_score_threshold(self, threshold: f32) -> Self
pub fn text_rec_score_threshold(self, threshold: f32) -> Self
Sets the text recognition score threshold.
§Arguments
thresh- The minimum score threshold for recognition results
§Returns
The updated builder instance
Sets the text recognition score threshold.
Results with confidence scores below this threshold will be filtered out.
§Arguments
threshold- The minimum score threshold for recognition results
§Returns
The updated builder instance
Sourcepub fn text_rec_input_shape(self, shape: (u32, u32, u32)) -> Self
pub fn text_rec_input_shape(self, shape: (u32, u32, u32)) -> Self
Sets the text recognition model input shape.
§Arguments
shape- The model input shape as (channels, height, width)
§Returns
The updated builder instance
Sets the text recognition model input shape.
§Arguments
shape- The model input shape as (channels, height, width)
§Returns
The updated builder instance
Sourcepub fn text_rec_character_dict_path(self, path: impl Into<PathBuf>) -> Self
pub fn text_rec_character_dict_path(self, path: impl Into<PathBuf>) -> Self
Sourcepub fn aspect_ratio_bucketing_config(
self,
config: AspectRatioBucketingConfig,
) -> Self
pub fn aspect_ratio_bucketing_config( self, config: AspectRatioBucketingConfig, ) -> Self
Enables aspect ratio bucketing for text recognition with default configuration.
This enables aspect ratio bucketing which groups images by aspect ratio ranges instead of exact dimensions, improving batch efficiency.
§Returns
The updated builder instance
Sets a custom aspect ratio bucketing configuration.
§Arguments
config- The aspect ratio bucketing configuration
§Returns
The updated builder instance
Sourcepub fn disable_aspect_ratio_bucketing(self) -> Self
pub fn disable_aspect_ratio_bucketing(self) -> Self
Disables aspect ratio bucketing (uses exact dimension grouping).
§Returns
The updated builder instance
Sourcepub fn dynamic_batching_config(self, config: DynamicBatchConfig) -> Self
pub fn dynamic_batching_config(self, config: DynamicBatchConfig) -> Self
Enables dynamic batching with default configuration.
This enables cross-image batching for both detection and recognition, which can improve performance when processing multiple images with compatible shapes.
§Returns
The updated builder instance
Sets a custom dynamic batching configuration.
§Arguments
config- The dynamic batching configuration
§Returns
The updated builder instance
Sourcepub fn disable_dynamic_batching(self) -> Self
pub fn disable_dynamic_batching(self) -> Self
Sourcepub fn max_detection_batch_size(self, batch_size: usize) -> Self
pub fn max_detection_batch_size(self, batch_size: usize) -> Self
Sourcepub fn max_recognition_batch_size(self, batch_size: usize) -> Self
pub fn max_recognition_batch_size(self, batch_size: usize) -> Self
Sourcepub fn min_batch_size(self, min_size: usize) -> Self
pub fn min_batch_size(self, min_size: usize) -> Self
Sourcepub fn shape_compatibility_strategy(
self,
strategy: ShapeCompatibilityStrategy,
) -> Self
pub fn shape_compatibility_strategy( self, strategy: ShapeCompatibilityStrategy, ) -> Self
Sourcepub fn aspect_ratio_tolerance(self, tolerance: f32) -> Self
pub fn aspect_ratio_tolerance(self, tolerance: f32) -> Self
Sourcepub fn exact_shape_matching(self) -> Self
pub fn exact_shape_matching(self) -> Self
Sets exact shape matching for dynamic batching.
This requires images to have identical dimensions to be batched together.
§Returns
The updated builder instance
Source§impl OAROCRBuilder
impl OAROCRBuilder
Sourcepub fn enable_dynamic_batching(self) -> Self
pub fn enable_dynamic_batching(self) -> Self
Enables dynamic batching with default configuration
Sourcepub fn enable_aspect_ratio_bucketing(self) -> Self
pub fn enable_aspect_ratio_bucketing(self) -> Self
Enables aspect ratio bucketing with default configuration
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OAROCRBuilder
impl RefUnwindSafe for OAROCRBuilder
impl Send for OAROCRBuilder
impl Sync for OAROCRBuilder
impl Unpin for OAROCRBuilder
impl UnwindSafe for OAROCRBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.