Repository: roboflow/supervision
File: supervision/keypoint/annotators.py (Python)

Code before:
                missing_b = np.allclose(xy_b, 0)
                if missing_a or missing_b:
                    continue

                cv2.line(
                    img=scene,
                    pt1=(int(xy_a[0]), int(xy_a[1])),
                    pt2=(int(xy_b[0]), int(xy_b[1])),
                    color=self.color.as_bgr(),
                    thickness=self.thickness,
                )

        return scene


class VertexLabelAnnotator:
    """
    A class for annotating vertex labels on an image using provided detections.
    """

    def __init__(
        self,
        color: Union[Color, List[Color]] = Color.ROBOFLOW,
        text_color: Color = Color.WHITE,
        text_scale: float = 0.5,
        text_thickness: int = 1,
        text_padding: int = 10,
        border_radius: int = 0,
    ):
        self.border_radius: int = border_radius
        self.color: Union[Color, List[Color]] = color
        self.text_color: Color = text_color
        self.text_scale: float = text_scale
        self.text_thickness: int = text_thickness
        self.text_padding: int = text_padding

    @staticmethod
    def get_text_bounding_box(
        text: str,
        font: int,
        text_scale: float,
        text_thickness: int,
        center_coordinates: Tuple[int, int],
    ) -> Tuple[int, int, int, int]:
        text_w, text_h = cv2.getTextSize(
            text=text,
            fontFace=font,
            fontScale=text_scale,
            thickness=text_thickness,
        )[0]
        center_x, center_y = center_coordinates

Review comment (suggestion):
Docs suggestions:

```
    """
    A class that draws rounded boxes and labels of skeleton vertices on images. It uses
    specified key points to determine the locations where the vertices should be
    drawn.

    Args:
        color (Union[Color, List[Color]], optional): The color to use for each keypoint
            label. If a list is provided, the colors will be used in order for each
            keypoint. Defaults to `Color.ROBOFLOW`.
        text_color (Color, optional): The color to use for the labels. Defaults to
            `Color.WHITE`.
        text_scale (float, optional): The scale of the text. Defaults to `0.5`.
        text_thickness (int, optional): The thickness of the text. Defaults to `1`.
        text_padding (int, optional): The padding around the text. Defaults to `10`.
        border_radius (int, optional): The radius of the rounded corners of the boxes.
            Set to a high value to produce circles. Defaults to `0`.
    """
    ```

Code after:
                return scene

            for class_a, class_b in edges:
                xy_a = xy[class_a - 1]
                xy_b = xy[class_b - 1]
                missing_a = np.allclose(xy_a, 0)
                missing_b = np.allclose(xy_b, 0)
                if missing_a or missing_b:
                    continue

                cv2.line(
                    img=scene,
                    pt1=(int(xy_a[0]), int(xy_a[1])),
                    pt2=(int(xy_b[0]), int(xy_b[1])),
                    color=self.color.as_bgr(),
                    thickness=self.thickness,
                )

        return scene


class VertexLabelAnnotator:
    """
    A class that draws labels of skeleton vertices on images. It uses specified key
    points to determine the locations where the vertices should be drawn.
    """

    def __init__(
        self,
        color: Union[Color, List[Color]] = Color.ROBOFLOW,
        text_color: Color = Color.WHITE,
        text_scale: float = 0.5,
        text_thickness: int = 1,
        text_padding: int = 10,
        border_radius: int = 0,
    ):
        """
        Args:
            color (Union[Color, List[Color]], optional): The color to use for each
                keypoint label. If a list is provided, the colors will be used in order
                for each keypoint.
            text_color (Color, optional): The color to use for the labels.
            text_scale (float, optional): The scale of the text.
            text_thickness (int, optional): The thickness of the text.
            text_padding (int, optional): The padding around the text.
            border_radius (int, optional): The radius of the rounded corners of the
                boxes. Set to a high value to produce circles.
        """
        self.border_radius: int = border_radius
        self.color: Union[Color, List[Color]] = color
        self.text_color: Color = text_color