from .bounding_box import BoundingBox
from dataclasses import InitVar, dataclass, field
from typing import Optional
[docs]
@dataclass(slots=True, kw_only=True)
class RandomAnnotation:
"""
A class to represent a random annotation for an image.
Attributes:
gt_name (str): The name of the ground truth of the annotation.
id (str): The unique identifier for the annotation.
category_id (int): The category ID of the annotation.
image_id (str): The identifier of the image the annotation belongs to.
bbox_coords (BoundingBox): The bounding box coordinates of the annotation.
unit_id (Optional[int]): The identifier of the unit this annotation belongs to (if units were computed).
"""
# Ground Truth properties
gt_name: str
# Annotation properties
id: str
category_id: int
image_id: str
bbox_coords: BoundingBox = field(init=False)
# Additional properties
unit_id: Optional[int] = field(default=None, init=False)
# Init-only fields
coordinates: InitVar[list[int]]
def __post_init__(self, coordinates: list[int]):
self.bbox_coords = BoundingBox(input_coords=coordinates)
def __str__(self):
annotation_string = "Annotation ID: " + str(self.id) + "\n"
annotation_string += "\tCategory in annotation: " + str(self.category_id) + "\n"
annotation_string += "\tImage ID: " + str(self.image_id) + "\n"
annotation_string += "\tBounding box coordinates: " + self.bbox_coords.__str__() + "\n"
return annotation_string