Skip to main content

Module utils

Module utils 

Source
Expand description

Utility functions for the OCR pipeline.

This module re-exports utilities from oar-ocr-core.

Modules§

bbox_crop
Bounding box based image cropping utilities.
cow
Copy-on-Write utilities for efficient image handling.
crop
Image cropping functionality with different modes.
dict
Dictionary and tokenizer loading utilities.
image
Utility functions for image processing.
tensor
Tensor utility functions for converting between vectors and tensors.
topk
Top-k classification result processing.
transform
Image transformation utilities for OCR processing.
validation
Reusable validation components for OCR tasks.

Structs§

BBoxCrop
Bounding box based image cropping utilities.
Crop
A processor for cropping images with different positioning modes.
OCRResizePadConfig
Configuration for OCR-style resize-and-pad operations with width constraints.
ResizePadConfig
Configuration for resize-and-pad operations.
ScoreValidator
A reusable validator for score ranges.
Topk
A processor for extracting top-k results from classification outputs.
TopkResult
Result structure for top-k classification processing.

Enums§

PaddingStrategy
Padding strategy for resize-and-pad operations.

Functions§

calculate_center_crop_coords
Calculates centered crop coordinates for a target size.
check_image_size
Checks if the given image size is valid (non-zero dimensions).
create_rgb_image
Creates an RgbImage from raw pixel data.
dynamic_to_gray
Converts a DynamicImage to a GrayImage.
dynamic_to_rgb
Converts a DynamicImage to an RgbImage.
get_rotate_crop_image
Extracts a rotated and cropped image from a source image based on bounding box points.
load_image
Loads an image from a file path and converts it to RgbImage.
load_images
Loads a batch of images from file paths.
load_images_batch_with_policy
Load multiple images from file paths using centralized parallel policy.
load_images_batch_with_threshold
Loads a batch of images from file paths with a custom parallel threshold.
mask_region
Masks a rectangular region in an RGB image with a solid color.
mask_regions
Masks multiple bounding box regions in an RGB image.
ocr_resize_and_pad
Resize an image for OCR processing with width constraints and padding.
pad_image
Pads an image to the specified dimensions with a fill color.
read_character_dict
Reads a character dictionary file and returns a vector of strings.
read_dict_content
Reads a character dictionary file and returns the raw content string.
require_path
Validates that a required path option is present and returns the path.
resize_and_pad
Resize an image to fit within target dimensions while maintaining aspect ratio, then pad to exact target dimensions.
resize_gray_image
Resizes a grayscale image to the target dimensions using Lanczos3 filtering.
resize_image
Resizes an RGB image to the target dimensions using Lanczos3 filtering.
resize_images_batch
Resizes a batch of images to the specified dimensions.
resize_images_batch_to_dynamic
Resizes a batch of images and converts them to DynamicImage format.
rgb_to_grayscale
Converts an RGB image to grayscale.
slice_gray_image
Extracts a rectangular region from a grayscale image.
slice_image
Extracts a rectangular region from an RGB image.
stack_tensor2d
Stacks a slice of 2D tensors into a single 3D tensor.
stack_tensor3d
Stacks a slice of 3D tensors into a single 4D tensor.
tensor1d_to_vec
Converts a 1D tensor into a 1D vector of f32 values.
tensor2d_to_vec
Converts a 2D tensor into a 2D vector of f32 values.
tensor3d_slice
Extracts a 2D slice from a 3D tensor at the specified index.
tensor3d_to_vec
Converts a 3D tensor into a 3D vector of f32 values.
tensor4d_slice
Extracts a 3D slice from a 4D tensor at the specified index.
tensor4d_to_vec
Converts a 4D tensor into a 4D vector of f32 values.
validate_crop_bounds
Validates that crop coordinates stay within image bounds.
validate_length_match
Validates that a vector’s length matches an expected size.
validate_max_value
Validates that a value doesn’t exceed a maximum.
validate_positive_dimensions
Validates that dimensions are positive (non-zero).
vec_to_tensor1d
Converts a 1D vector of f32 values into a 1D tensor with the specified shape.
vec_to_tensor2d
Converts a 2D vector of f32 values into a 2D tensor.
vec_to_tensor3d
Converts a 3D vector of f32 values into a 3D tensor.
vec_to_tensor4d
Converts a 4D vector of f32 values into a 4D tensor.