OCRResize

Struct OCRResize 

Source
pub struct OCRResize {
    pub rec_image_shape: [usize; 3],
    pub input_shape: Option<[usize; 3]>,
    pub max_img_w: usize,
}
Expand description

OCR-specific image resizer.

This struct handles resizing of images for OCR processing. It supports both dynamic resizing based on the image’s width-to-height ratio and static resizing to fixed dimensions.

Fields§

§rec_image_shape: [usize; 3]§input_shape: Option<[usize; 3]>§max_img_w: usize

Implementations§

Source§

impl OCRResize

Source

pub fn new( rec_image_shape: Option<[usize; 3]>, input_shape: Option<[usize; 3]>, ) -> Self

Creates a new OCRResize instance with default maximum width.

§Arguments
  • rec_image_shape - Optional shape for recognition images [channels, height, width]. If None, uses DEFAULT_REC_IMAGE_SHAPE.
  • input_shape - Optional input shape [channels, height, width].
§Returns

A new OCRResize instance.

Source

pub fn with_max_width( rec_image_shape: Option<[usize; 3]>, input_shape: Option<[usize; 3]>, max_img_w: Option<usize>, ) -> Self

Creates a new OCRResize instance with custom maximum width.

§Arguments
  • rec_image_shape - Optional shape for recognition images [channels, height, width]. If None, uses DEFAULT_REC_IMAGE_SHAPE.
  • input_shape - Optional input shape [channels, height, width].
  • max_img_w - Optional maximum image width. If None, uses DEFAULT_MAX_IMG_WIDTH.
§Returns

A new OCRResize instance.

Source

pub fn resize_img(&self, img: &RgbImage, max_wh_ratio: f32) -> RgbImage

Resizes an image based on a maximum width-to-height ratio.

This method resizes an image to fit within the specified dimensions while maintaining the aspect ratio. If the calculated width exceeds the maximum allowed width, the image is resized to the maximum width.

§Arguments
  • img - The input RGB image to resize.
  • max_wh_ratio - The maximum width-to-height ratio for the resized image.
§Returns

A resized and padded RGB image.

Source

pub fn resize(&self, img: &RgbImage) -> RgbImage

Resizes an image using the default width-to-height ratio from rec_image_shape.

This method calculates the width-to-height ratio from the configured rec_image_shape and uses it to resize the image via resize_img.

§Arguments
  • img - The input RGB image to resize.
§Returns

A resized and padded RGB image.

Source

pub fn static_resize(&self, img: &RgbImage) -> Result<RgbImage, OCRError>

Resizes an image to a static size defined by input_shape.

This method resizes an image to exact dimensions specified in the input_shape. It requires input_shape to be configured, otherwise it returns a ConfigError.

§Arguments
  • img - The input RGB image to resize.
§Returns

A resized RGB image or an OCRError if input_shape is not configured.

Source

pub fn apply(&self, imgs: &[RgbImage]) -> Result<Vec<RgbImage>, OCRError>

Applies resizing to a batch of images.

This method applies either dynamic resizing (using resize) or static resizing (using static_resize) to a batch of images, depending on whether input_shape is configured. If input_shape is None, dynamic resizing is used; otherwise, static resizing is used.

§Arguments
  • imgs - A slice of RGB images to resize.
§Returns

A vector of resized RGB images or an OCRError if static resizing fails.

Source

pub fn resize_to_tensor_shape( &self, img: &RgbImage, ) -> Result<RgbImage, OCRError>

Resizes an image to fit tensor shape requirements.

This method resizes an image to fit within the dimensions specified by rec_image_shape, while maintaining the aspect ratio. If the calculated width exceeds the maximum allowed width, the image is resized to the maximum width. The resulting image is padded to match the target dimensions.

§Arguments
  • img - The input RGB image to resize.
§Returns

A resized and padded RGB image or an OCRError.

Source

pub fn apply_to_images( &self, imgs: &[RgbImage], ) -> Result<Vec<RgbImage>, OCRError>

Applies tensor shape resizing to a batch of images.

This method applies resize_to_tensor_shape to a batch of images. It handles empty batches by returning an empty vector.

§Arguments
  • imgs - A slice of RGB images to resize.
§Returns

A vector of resized RGB images or an OCRError if resizing fails.

Trait Implementations§

Source§

impl Debug for OCRResize

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