Process
Utility functions for processing model input/output.
INTERPOLATION_MAP
module-attribute
¶
INTERPOLATION_MAP: dict[ImageInterpolation, int] = {
"nearest": INTER_NEAREST,
"linear": INTER_LINEAR,
"cubic": INTER_CUBIC,
"area": INTER_AREA,
"lanczos4": INTER_LANCZOS4,
}
Mapping from interpolation method name to OpenCV constant.
read_plate_image ¶
read_plate_image(
image_path: PathLike,
image_color_mode: ImageColorMode = "grayscale",
) -> ndarray
Reads an image from disk in the requested colour mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_path
|
PathLike
|
Path to the image file. |
required |
image_color_mode
|
ImageColorMode
|
|
'grayscale'
|
Returns:
Type | Description |
---|---|
ndarray
|
The image as a NumPy array.
Grayscale images have shape |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the image file does not exist. |
ValueError
|
If the image cannot be decoded. |
Source code in fast_plate_ocr/core/process.py
resize_image ¶
resize_image(
img: ndarray,
img_height: int,
img_width: int,
image_color_mode: ImageColorMode = "grayscale",
keep_aspect_ratio: bool = False,
interpolation_method: ImageInterpolation = "linear",
padding_color: PaddingColor = (114, 114, 114),
) -> ndarray
Resizes an in-memory image with optional aspect-ratio preservation and padding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
Input image. |
required |
img_height
|
int
|
Target image height. |
required |
img_width
|
int
|
Target image width. |
required |
image_color_mode
|
ImageColorMode
|
Output colour mode, |
'grayscale'
|
keep_aspect_ratio
|
bool
|
If |
False
|
interpolation_method
|
ImageInterpolation
|
Interpolation method used for resizing. Defaults to |
'linear'
|
padding_color
|
PaddingColor
|
Padding colour (scalar for grayscale, tuple for RGB). Defaults to
|
(114, 114, 114)
|
Returns:
Type | Description |
---|---|
ndarray
|
The resized image with shape |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in fast_plate_ocr/core/process.py
read_and_resize_plate_image ¶
read_and_resize_plate_image(
image_path: PathLike,
img_height: int,
img_width: int,
image_color_mode: ImageColorMode = "grayscale",
keep_aspect_ratio: bool = False,
interpolation_method: ImageInterpolation = "linear",
padding_color: PaddingColor = (114, 114, 114),
) -> ndarray
Reads an image from disk and resizes it for model input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_path
|
PathLike
|
Path to the image. |
required |
img_height
|
int
|
Desired output height. |
required |
img_width
|
int
|
Desired output width. |
required |
image_color_mode
|
ImageColorMode
|
|
'grayscale'
|
keep_aspect_ratio
|
bool
|
Whether to preserve aspect ratio via letter-boxing. Defaults to
|
False
|
interpolation_method
|
ImageInterpolation
|
Interpolation method to use. Defaults to |
'linear'
|
padding_color
|
PaddingColor
|
Colour used for padding when aspect ratio is preserved. Defaults to
|
(114, 114, 114)
|
Returns:
Type | Description |
---|---|
ndarray
|
The resized (and possibly padded) image with shape |
Source code in fast_plate_ocr/core/process.py
preprocess_image ¶
Converts image data to the format expected by the model.
The model itself handles pixel-value normalisation, so this function only ensures the batch-dimension and dtype are correct.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images
|
ndarray
|
Image or batch of images with shape |
required |
Returns:
Type | Description |
---|---|
ndarray
|
A NumPy array with shape |
Raises:
Type | Description |
---|---|
ValueError
|
If the input does not have 3 or 4 dimensions. |
Source code in fast_plate_ocr/core/process.py
postprocess_output ¶
postprocess_output(
model_output: ndarray,
max_plate_slots: int,
model_alphabet: str,
return_confidence: bool = False,
) -> tuple[list[str], ndarray] | list[str]
Decodes model predictions into licence-plate strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_output
|
ndarray
|
Raw output tensor from the model. |
required |
max_plate_slots
|
int
|
Maximum number of character positions. |
required |
model_alphabet
|
str
|
Alphabet used by the model. |
required |
return_confidence
|
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
tuple[list[str], ndarray] | list[str]
|
If
|