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: usizeImplementations§
Source§impl OCRResize
impl OCRResize
Sourcepub fn with_max_width(
rec_image_shape: Option<[usize; 3]>,
input_shape: Option<[usize; 3]>,
max_img_w: Option<usize>,
) -> Self
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.
Sourcepub fn resize_img(&self, img: &RgbImage, max_wh_ratio: f32) -> RgbImage
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.
Sourcepub fn resize(&self, img: &RgbImage) -> RgbImage
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.
Sourcepub fn static_resize(&self, img: &RgbImage) -> Result<RgbImage, OCRError>
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.
Sourcepub fn apply(&self, imgs: &[RgbImage]) -> Result<Vec<RgbImage>, OCRError>
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.
Sourcepub fn resize_to_tensor_shape(
&self,
img: &RgbImage,
) -> Result<RgbImage, OCRError>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OCRResize
impl RefUnwindSafe for OCRResize
impl Send for OCRResize
impl Sync for OCRResize
impl Unpin for OCRResize
impl UnwindSafe for OCRResize
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.