Process Helpers¶
These are lower-level preprocessing and postprocessing helpers used by the inference pipeline. Most users should
interact with LicensePlateRecognizer instead of calling these functions directly.
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,
pad_char: str | None = None,
remove_pad_char: bool = True,
return_confidence: bool = False,
return_region: bool = False,
region_output: ndarray | None = None,
region_labels: Sequence[str] | None = None,
) -> list[PlatePrediction]
Decode model outputs into per-image predictions.
This function converts raw model outputs into decoded license plate strings and (optionally) per-character confidence scores and region predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
ndarray
|
Raw output tensor for the plate head. Expected shape is compatible with
|
required |
max_plate_slots
|
int
|
Maximum number of character positions predicted by the model. |
required |
model_alphabet
|
str
|
Alphabet used by the model; index positions correspond to model classes. |
required |
pad_char
|
str | None
|
Padding character used during training/inference config. When provided and
|
None
|
remove_pad_char
|
bool
|
If |
True
|
return_confidence
|
bool
|
If |
False
|
return_region
|
bool
|
If |
False
|
region_output
|
ndarray | None
|
Optional region probabilities/logits of shape |
None
|
region_labels
|
Sequence[str] | None
|
Sequence mapping region indices to human-readable labels. |
None
|
Returns:
| Type | Description |
|---|---|
list[PlatePrediction]
|
A list of |
list[PlatePrediction]
|
|
list[PlatePrediction]
|
|
list[PlatePrediction]
|
|
list[PlatePrediction]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in fast_plate_ocr/core/process.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |