Label, RichLabel VertexLabel annotators: rename 'smart_positions' arg to 'smart_position'

This commit is contained in:
LinasKo 2024-11-11 15:03:52 +02:00
parent 38dbf5d05d
commit 79b45a4ea8
2 changed files with 12 additions and 12 deletions

View File

@ -1056,7 +1056,7 @@ class LabelAnnotator(BaseAnnotator):
text_position: Position = Position.TOP_LEFT,
color_lookup: ColorLookup = ColorLookup.CLASS,
border_radius: int = 0,
smart_positions: bool = False,
smart_position: bool = False,
):
"""
Args:
@ -1073,7 +1073,7 @@ class LabelAnnotator(BaseAnnotator):
Options are `INDEX`, `CLASS`, `TRACK`.
border_radius (int): The radius to apply round edges. If the selected
value is higher than the lower dimension, width or height, is clipped.
smart_positions (bool): Spread out the labels to avoid overlapping.
smart_position (bool): Spread out the labels to avoid overlapping.
"""
self.border_radius: int = border_radius
self.color: Union[Color, ColorPalette] = color
@ -1083,7 +1083,7 @@ class LabelAnnotator(BaseAnnotator):
self.text_padding: int = text_padding
self.text_anchor: Position = text_position
self.color_lookup: ColorLookup = color_lookup
self.smart_positions = smart_positions
self.smart_position = smart_position
@ensure_cv2_image_for_annotation
def annotate(
@ -1141,7 +1141,7 @@ class LabelAnnotator(BaseAnnotator):
label_properties = self._get_label_properties(detections, labels)
xyxy = label_properties[:, :4]
if self.smart_positions:
if self.smart_position:
xyxy = spread_out_boxes(xyxy)
label_properties[:, :4] = xyxy
@ -1331,7 +1331,7 @@ class RichLabelAnnotator(BaseAnnotator):
text_position: Position = Position.TOP_LEFT,
color_lookup: ColorLookup = ColorLookup.CLASS,
border_radius: int = 0,
smart_positions: bool = False,
smart_position: bool = False,
):
"""
Args:
@ -1348,7 +1348,7 @@ class RichLabelAnnotator(BaseAnnotator):
Options are `INDEX`, `CLASS`, `TRACK`.
border_radius (int): The radius to apply round edges. If the selected
value is higher than the lower dimension, width or height, is clipped.
smart_positions (bool): Spread out the labels to avoid overlapping.
smart_position (bool): Spread out the labels to avoid overlapping.
"""
self.color = color
self.text_color = text_color
@ -1356,7 +1356,7 @@ class RichLabelAnnotator(BaseAnnotator):
self.text_anchor = text_position
self.color_lookup = color_lookup
self.border_radius = border_radius
self.smart_positions = smart_positions
self.smart_position = smart_position
self.font = self._load_font(font_size, font_path)
@ensure_pil_image_for_annotation
@ -1414,7 +1414,7 @@ class RichLabelAnnotator(BaseAnnotator):
label_properties = self._get_label_properties(draw, detections, labels)
xyxy = label_properties[:, :4]
if self.smart_positions:
if self.smart_position:
xyxy = spread_out_boxes(xyxy)
label_properties[:, :4] = xyxy

View File

@ -202,7 +202,7 @@ class VertexLabelAnnotator:
text_thickness: int = 1,
text_padding: int = 10,
border_radius: int = 0,
smart_positions: bool = False,
smart_position: bool = False,
):
"""
Args:
@ -217,7 +217,7 @@ class VertexLabelAnnotator:
text_padding (int): The padding around the text.
border_radius (int): The radius of the rounded corners of the
boxes. Set to a high value to produce circles.
smart_positions (bool): Spread out the labels to avoid overlap.
smart_position (bool): Spread out the labels to avoid overlap.
"""
self.border_radius: int = border_radius
self.color: Union[Color, List[Color]] = color
@ -225,7 +225,7 @@ class VertexLabelAnnotator:
self.text_scale: float = text_scale
self.text_thickness: int = text_thickness
self.text_padding: int = text_padding
self.smart_positions = smart_positions
self.smart_position = smart_position
def annotate(
self,
@ -362,7 +362,7 @@ class VertexLabelAnnotator:
)
xyxy_padded = pad_boxes(xyxy=xyxy, px=self.text_padding)
if self.smart_positions:
if self.smart_position:
xyxy_padded = spread_out_boxes(xyxy_padded)
xyxy = pad_boxes(xyxy=xyxy_padded, px=-self.text_padding)