OAROCRBuilder

Struct OAROCRBuilder 

Source
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

Source

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 file
  • text_recognition_model_path - Path to the text recognition model file
  • text_rec_character_dict_path - Path to the character dictionary file
§Returns

A new OAROCRBuilder instance

Source

pub fn from_config(config: OAROCRConfig) -> Self

Creates a new OAROCRBuilder from an existing configuration.

§Arguments
  • config - The OAROCRConfig to use
§Returns

A new OAROCRBuilder instance

Source

pub fn doc_orientation_classify_model_name(self, name: String) -> Self

Sets the document orientation classification model name.

§Arguments
  • name - The model name
§Returns

The updated builder instance

Source

pub fn doc_orientation_classify_model_path( self, path: impl Into<PathBuf>, ) -> Self

Sets the document orientation classification model path.

§Arguments
  • path - The path to the model file
§Returns

The updated builder instance

Source

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

Source

pub fn doc_unwarping_model_name(self, name: String) -> Self

Sets the document unwarping model name.

§Arguments
  • name - The model name
§Returns

The updated builder instance

Source

pub fn doc_unwarping_model_path(self, path: impl Into<PathBuf>) -> Self

Sets the document unwarping model path.

§Arguments
  • path - The path to the model file
§Returns

The updated builder instance

Source

pub fn text_detection_model_name(self, name: String) -> Self

Sets the text detection model name.

§Arguments
  • name - The model name
§Returns

The updated builder instance

Source

pub fn text_detection_model_path(self, path: impl Into<PathBuf>) -> Self

Sets the text detection model path.

§Arguments
  • path - The path to the model file
§Returns

The updated builder instance

Source

pub fn text_detection_batch_size(self, batch_size: usize) -> Self

Sets the text detection batch size.

§Arguments
  • batch_size - The batch size for inference
§Returns

The updated builder instance

Source

pub fn text_recognition_model_name(self, name: String) -> Self

Sets the text recognition model name.

§Arguments
  • name - The model name
§Returns

The updated builder instance

Source

pub fn text_recognition_model_path(self, path: impl Into<PathBuf>) -> Self

Sets the text recognition model path.

§Arguments
  • path - The path to the model file
§Returns

The updated builder instance

Source

pub fn text_recognition_batch_size(self, batch_size: usize) -> Self

Sets the text recognition batch size.

§Arguments
  • batch_size - The batch size for inference
§Returns

The updated builder instance

Source

pub fn textline_orientation_classify_model_name(self, name: String) -> Self

Sets the text line orientation classification model name.

§Arguments
  • name - The model name
§Returns

The updated builder instance

Source

pub fn textline_orientation_classify_model_path( self, path: impl Into<PathBuf>, ) -> Self

Sets the text line orientation classification model path.

§Arguments
  • path - The path to the model file
§Returns

The updated builder instance

Source

pub fn textline_orientation_classify_batch_size(self, batch_size: usize) -> Self

Sets the text line orientation classification batch size.

§Arguments
  • batch_size - The batch size for inference
§Returns

The updated builder instance

Source

pub fn textline_orientation_input_shape(self, shape: (u32, u32)) -> Self

Sets the text line orientation classification input shape.

§Arguments
  • shape - The input shape as (width, height)
§Returns

The updated builder instance

Sets the text line orientation classifier input shape.

§Arguments
  • shape - The input shape as (width, height)
§Returns

The updated builder instance

Source

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

Source

pub fn use_doc_orientation_classify(self, use_it: bool) -> Self

Sets whether to use document orientation classification.

§Arguments
  • use_it - Whether to use document orientation classification
§Returns

The updated builder instance

Source

pub fn use_doc_unwarping(self, use_it: bool) -> Self

Sets whether to use document unwarping.

§Arguments
  • use_it - Whether to use document unwarping
§Returns

The updated builder instance

Source

pub fn use_textline_orientation(self, use_it: bool) -> Self

Sets whether to use text line orientation classification.

§Arguments
  • use_it - Whether to use text line orientation classification
§Returns

The updated builder instance

Source

pub fn parallel_policy(self, policy: ParallelPolicy) -> Self

Sets the parallel processing policy for the pipeline.

§Arguments
  • policy - The parallel processing policy configuration
§Returns

The updated builder instance

Source

pub fn text_detection_ort_session(self, config: OrtSessionConfig) -> Self

Sets the ONNX Runtime session configuration for text detection.

§Arguments
  • config - The ONNX Runtime session configuration
§Returns

The updated builder instance

Source

pub fn text_recognition_ort_session(self, config: OrtSessionConfig) -> Self

Sets the ONNX Runtime session configuration for text recognition.

§Arguments
  • config - The ONNX Runtime session configuration
§Returns

The updated builder instance

Source

pub fn textline_orientation_ort_session(self, config: OrtSessionConfig) -> Self

Sets the ONNX Runtime session configuration for text line orientation classification.

§Arguments
  • config - The ONNX Runtime session configuration
§Returns

The updated builder instance

Source

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

Source

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 processing
Source

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 resources
Source

pub fn text_detection_session_pool_size(self, size: usize) -> Self

Sets the session pool size for text detection.

§Arguments
  • size - The session pool size (minimum 1)
§Returns

The updated builder instance

Source

pub fn text_recognition_session_pool_size(self, size: usize) -> Self

Sets the session pool size for text recognition.

§Arguments
  • size - The session pool size (minimum 1)
§Returns

The updated builder instance

Source

pub fn textline_orientation_session_pool_size(self, size: usize) -> Self

Sets the session pool size for text line orientation classification.

§Arguments
  • size - The session pool size (minimum 1)
§Returns

The updated builder instance

Source

pub fn global_session_pool_size(self, size: usize) -> Self

Sets the session pool size for all components.

This is a convenience method that applies the same session pool size to text detection, text recognition, and text line orientation classification.

§Arguments
  • size - The session pool size (minimum 1)
§Returns

The updated builder instance

Source

pub fn text_det_limit_side_len(self, limit: u32) -> Self

Sets the text detection limit side length.

§Arguments
  • limit - The maximum side length for resizing
§Returns

The updated builder instance

Source

pub fn text_det_limit_type(self, limit_type: LimitType) -> Self

Sets the text detection limit type.

§Arguments
  • limit_type - The type of limit for resizing
§Returns

The updated builder instance

Source

pub fn text_det_input_shape(self, shape: (u32, u32, u32)) -> Self

Sets the text detection input shape.

§Arguments
  • shape - The input shape as (channels, height, width)
§Returns

The updated builder instance

Source

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 images
Source

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 detection

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
  • threshold - The binarization threshold (default: 0.3)
§Returns

The updated builder instance

Source

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 boxes

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
  • threshold - The box score threshold (default: 0.6)
§Returns

The updated builder instance

Source

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 capture
Source

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

Source

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

Source

pub fn text_rec_character_dict_path(self, path: impl Into<PathBuf>) -> Self

Sets the text recognition character dictionary path.

§Arguments
  • path - The path to the character dictionary file
§Returns

The updated builder instance

Source

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

Source

pub fn disable_aspect_ratio_bucketing(self) -> Self

Disables aspect ratio bucketing (uses exact dimension grouping).

§Returns

The updated builder instance

Source

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

Source

pub fn disable_dynamic_batching(self) -> Self

Disables dynamic batching (processes images individually).

§Returns

The updated builder instance

Source

pub fn max_detection_batch_size(self, batch_size: usize) -> Self

Sets the maximum batch size for detection.

§Arguments
  • batch_size - Maximum number of images to batch for detection
§Returns

The updated builder instance

Source

pub fn max_recognition_batch_size(self, batch_size: usize) -> Self

Sets the maximum batch size for recognition.

§Arguments
  • batch_size - Maximum number of text regions to batch for recognition
§Returns

The updated builder instance

Source

pub fn min_batch_size(self, min_size: usize) -> Self

Sets the minimum batch size to trigger dynamic batching.

§Arguments
  • min_size - Minimum number of items needed to enable batching
§Returns

The updated builder instance

Source

pub fn shape_compatibility_strategy( self, strategy: ShapeCompatibilityStrategy, ) -> Self

Sets the shape compatibility strategy for dynamic batching.

§Arguments
  • strategy - The shape compatibility strategy to use
§Returns

The updated builder instance

Source

pub fn aspect_ratio_tolerance(self, tolerance: f32) -> Self

Sets aspect ratio tolerance for shape compatibility.

This is a convenience method that sets the shape compatibility strategy to AspectRatio with the specified tolerance.

§Arguments
  • tolerance - Tolerance for aspect ratio matching (e.g., 0.1 means ±10%)
§Returns

The updated builder instance

Source

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

pub fn build(self) -> OcrResult<OAROCR>

Builds the OAROCR instance with the configured parameters.

§Returns

A Result containing the OAROCR instance or an OCRError

Source§

impl OAROCRBuilder

Source

pub fn enable_dynamic_batching(self) -> Self

Enables dynamic batching with default configuration

Source

pub fn enable_aspect_ratio_bucketing(self) -> Self

Enables aspect ratio bucketing with default configuration

Trait Implementations§

Source§

impl Debug for OAROCRBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more