Skip to main content

plot

Signature:

Detection.plot(
image: PIL.Image.Image | str | numpy.ndarray,
results: list[DetectionResult],
as_image: bool = True,
) -> Image | numpy.ndarray

Description:

Draw detection boxes and class labels on the image.

Parameters:

Parameter

Type

Default

Description

image

PIL.Image.Image | str | numpy.ndarray

Required

Original input image, image file path, or NumPy array.

results

list[DetectionResult]

Required

Detection results returned by detect().

as_image

bool

True

Whether to return Image object; returns NumPy array when False.

Returns:

Image | numpy.ndarray

Raises:

TypeError: image type not supported.

ValueError: Image file read failed.

Example:

from boosteros.brain import Detection
from boosteros.robots.booster import BoosterRobot

robot = BoosterRobot()
detector = Detection(model="soccer")

image = robot.get_image(img_type="rgb")
results = detector.detect(image.to_numpy(), confidence=0.4)
image_with_boxes = detector.plot(image.to_numpy(), results, as_image=True)
image_with_boxes.save("detections.png")