🛠Pipelines Overview¶
License Plate Detection¶
🚗 License Plate Detection allows you to detect and identify license plates in images using a specialized pipeline based on the YOLOv9 model.
The LicensePlateDetector
is specialized for license plate detection. It utilizes the YOLOv9 object detection model to recognize license plates in images.
Bases: YoloV9ObjectDetector
Specialized detector for license plates using YoloV9 model. Inherits from YoloV9ObjectDetector and sets up license plate specific configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detection_model
|
PlateDetectorModel
|
Detection model to use, see |
required |
conf_thresh
|
float
|
Confidence threshold for filtering predictions. |
0.25
|
providers
|
Sequence[str | tuple[str, dict]] | None
|
Optional sequence of providers in order of decreasing precedence. If not specified, all available providers are used. |
None
|
sess_options
|
SessionOptions
|
Advanced session options for ONNX Runtime. |
None
|
Source code in open_image_models/detection/pipeline/license_plate.py
predict ¶
predict(images: ndarray) -> list[DetectionResult]
predict(
images: list[ndarray],
) -> list[list[DetectionResult]]
predict(images: str) -> list[DetectionResult]
predict(images: list[str]) -> list[list[DetectionResult]]
predict(images: PathLike[str]) -> list[DetectionResult]
predict(
images: list[PathLike[str]],
) -> list[list[DetectionResult]]
predict(
images: Any,
) -> list[DetectionResult] | list[list[DetectionResult]]
Perform license plate detection on one or multiple images.
This method is a specialized version of the YoloV9ObjectDetector.predict
method,
focusing on detecting license plates in images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images
|
Any
|
A single image as a numpy array, a single image path as a string, a list of images as numpy arrays, or a list of image file paths. |
required |
Returns:
Type | Description |
---|---|
list[DetectionResult] | list[list[DetectionResult]]
|
A list of |
Example usage:
from open_image_models import LicensePlateDetector
lp_detector = LicensePlateDetector(detection_model="yolo-v9-t-384-license-plate-end2end")
lp_detector.predict("path/to/license_plate_image.jpg")
Raises:
Type | Description |
---|---|
ValueError
|
If the image could not be loaded or processed. |
Source code in open_image_models/detection/pipeline/license_plate.py
Core API Documentation¶
The core
module provides base classes and protocols for object detection models, including essential data structures like BoundingBox
and DetectionResult
.
🔧 Core Components¶
The following components are used across detection pipelines and models:
BoundingBox
: Represents a bounding box for detected objects.DetectionResult
: Stores label, confidence, and bounding box for a detection.ObjectDetector
: Protocol defining essential methods likepredict
,show_benchmark
, anddisplay_predictions
.
BoundingBox
dataclass
¶
Represents a bounding box with top-left and bottom-right coordinates.
center
property
¶
Returns the (x, y) coordinates of the center of the bounding box.
intersection ¶
intersection(other: BoundingBox) -> Optional[BoundingBox]
Returns the intersection of this bounding box with another bounding box. If they do not intersect, returns None.
Source code in open_image_models/detection/core/base.py
iou ¶
iou(other: BoundingBox) -> float
Computes the Intersection-over-Union (IoU) between this bounding box and another bounding box.
Source code in open_image_models/detection/core/base.py
to_xywh ¶
Converts bounding box to (x, y, width, height) format, where (x, y) is the top-left corner.
:returns: A tuple containing the top-left x and y coordinates, width, and height of the bounding box.
Source code in open_image_models/detection/core/base.py
clamp ¶
clamp(max_width: int, max_height: int) -> BoundingBox
Returns a new BoundingBox
with coordinates clamped within the range [0, max_width] and [0, max_height].
:param max_width: The maximum width.
:param max_height: The maximum height.
:return: A new, clamped BoundingBox
.
Source code in open_image_models/detection/core/base.py
is_valid ¶
Checks if the bounding box is valid by ensuring that:
- The coordinates are in the correct order (x1 < x2 and y1 < y2).
- The bounding box lies entirely within the frame boundaries.
:param frame_width: The width of the frame. :param frame_height: The height of the frame. :return: True if the bounding box is valid, False otherwise.
Source code in open_image_models/detection/core/base.py
DetectionResult
dataclass
¶
DetectionResult(
label: str, confidence: float, bounding_box: BoundingBox
)
Represents the result of an object detection.
from_detection_data
classmethod
¶
from_detection_data(
bbox_data: tuple[int, int, int, int],
confidence: float,
class_id: str,
) -> DetectionResult
Creates a DetectionResult
instance from bounding box data, confidence, and a class label.
:param bbox_data: A tuple containing bounding box coordinates (x1, y1, x2, y2).
:param confidence: The detection confidence score.
:param class_id: The detected class label as a string.
:return: A DetectionResult
instance.
Source code in open_image_models/detection/core/base.py
ObjectDetector ¶
Bases: Protocol
predict ¶
predict(
images: Any,
) -> list[DetectionResult] | list[list[DetectionResult]]
Perform object detection on one or multiple images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images
|
Any
|
A single image as a numpy array, a single image path as a string, a list of images as numpy arrays, or a list of image file paths. |
required |
Returns:
Type | Description |
---|---|
list[DetectionResult] | list[list[DetectionResult]]
|
A list of DetectionResult for a single image input, |
list[DetectionResult] | list[list[DetectionResult]]
|
or a list of lists of DetectionResult for multiple images. |
Source code in open_image_models/detection/core/base.py
show_benchmark ¶
Display the benchmark results of the model with a single random image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_runs
|
int
|
Number of times to run inference on the image for averaging. |
10
|
Displays
Model information and benchmark results in a formatted table.
Source code in open_image_models/detection/core/base.py
display_predictions ¶
Run object detection on the input image and display the predictions on the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
An input image as a numpy array. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The image with bounding boxes and labels drawn on it. |
Source code in open_image_models/detection/core/base.py
Open Image Models HUB.
PlateDetectorModel
module-attribute
¶
PlateDetectorModel = Literal[
"yolo-v9-s-608-license-plate-end2end",
"yolo-v9-t-640-license-plate-end2end",
"yolo-v9-t-512-license-plate-end2end",
"yolo-v9-t-416-license-plate-end2end",
"yolo-v9-t-384-license-plate-end2end",
"yolo-v9-t-256-license-plate-end2end",
]
Available ONNX models for doing detection.