Annotations

class mira.core.Annotation(category, x1=None, y1=None, x2=None, y2=None, points=None, score=None, metadata=None)[source]

Defines a single annotation.

Parameters
  • selection – The selection associated with the annotation

  • category (Category) – The category of the annotation

  • score (Optional[float]) – A score for the annotation

  • metadata (Optional[dict]) – Metadata to store as part of the annotation

area()[source]

Compute the area of the selection.

Return type

int

assign(**kwargs)[source]

Get a new Annotation with only the supplied keyword arguments changed.

Return type

Annotation

convert(categories)[source]

Convert an annotation to match another annotation config.

Return type

Annotation

crop(width, height)[source]

Crop a selection to a given image width and height.

Parameters
  • width – The width of the image

  • height – The height of the image

draw(image, color, opaque=False, thickness=5)[source]

Draw selection onto given image.

Parameters
  • image (ndarray) – The image to draw on.

  • color (Union[Tuple[int, int, int], Tuple[int, int, int, int], int]) – The color to use.

  • opaque (bool) – Whether the box should be filled.

  • thickness (int) – The thickness of the box (for non-opaque cases only).

Returns

The image with the selection drawn

extract(image, pad=0)[source]

Extract selection from image (i.e., crop the image to the selection).

resize(scale)[source]

Obtain a revised selection with a given uniform scaling. Scale should be provided as either a single float or as an array with scaling factors provided as [sx, sy]

Return type

Annotation

x1y1x2y2()[source]

The simple bounding box containing the selection.

Return type

Tuple[int, int, int, int]

Returns

The coordinates (x1, y1, x2, y2). The first set always correspond with the top left of the image. The second set always correspond with the bottom right of the image.

xywh()[source]

Get the bounding box as x, y, width and height.

Return type

Tuple[int, int, int, int]

class mira.core.Categories(names)[source]

A class defining a list of annotation types for an object detection class.

Parameters

names (List[str]) – The list of class names

bboxes_from_group(annotations)[source]

Obtain an array of shape (N, 5) where the columns are x1, y1, x2, y2, class_index where class_index is determined from the annotation configuration.

classmethod from_categories(categories)[source]

Convert a list of strings to categories if it is not already.

Return type

Categories

index(category)[source]

Get the index for a category.

property types

Get the list of types.