flow_inference.image_processing.ImageHandler

class flow_inference.image_processing.ImageHandler(processor, target_image_size=None)[source]

Prepare document line images for TrOCR inference.

The handler converts raw image inputs to RGB PIL images, optionally resizes them to a configured target size, and applies a TrOCR processor to produce pixel tensors for model inference.

Parameters:
  • processor (TrOCRProcessor)

  • target_image_size (Tuple[int, int])

__init__(processor, target_image_size=None)[source]

Initialize the image handler.

Parameters:
  • processor (TrOCRProcessor) – TrOCR processor used to convert images into model tensors.

  • target_image_size (Tuple[int, int]) – Optional target image size as (width, height).

Methods

__init__(processor[, target_image_size])

Initialize the image handler.

handle_image(record)

Extract, normalize, resize, and process an image record.

load_image_from_bytes(image_bytes)

Load an RGB image from raw bytes.

process_image(image)

Convert a PIL image into a TrOCR pixel tensor.

resize_with_aspect_ratio(image)

Resize an image to the target size while preserving aspect ratio.