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

Code before:
        self,
        icon_path: str,
        position: Position = Position.TOP_CENTER,
        icon_size: float = 0.2,
        color: Union[Color, ColorPalette] = ColorPalette.default(),
        color_lookup: ColorLookup = ColorLookup.CLASS,
    ):
        """
        Args:
            icon_path (str): path of the icon in png format.
            position (Position): The position of the icon. Defaults to
                `TOP_CENTER`.
            icon_size (float): Represents the fraction of the original icon size to
              be displayed, with a default value of 0.2
              (equivalent to 20% of the original size).
            color (Union[Color, ColorPalette]): The color to draw the trace, can be
                a single color or a color palette.
            color_lookup (str): Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACE`.
        """
        self.color: Union[Color, ColorPalette] = color
        self.color_lookup: ColorLookup = color_lookup
        self.position = position
        icon = cv2.imread(icon_path, cv2.IMREAD_UNCHANGED)
        if icon is None:
            print(f"Error: Couldn't load the icon image from {icon_path}")
            return

        resized_icon_h, resized_icon_w = (
            int(icon.shape[0] * icon_size),
            int(icon.shape[1] * icon_size),
        )
        self.icon = cv2.resize(
            icon, (resized_icon_h, resized_icon_w), interpolation=cv2.INTER_AREA
        )

    def annotate(
        self,
        scene: np.ndarray,
        detections: Detections,
        custom_color_lookup: Optional[np.ndarray] = None,
    ) -> np.ndarray:
        """
        Annotates the given scene with icons based on the provided detections.
        Args:
            scene (np.ndarray): The image where bounding boxes will be drawn.
            detections (Detections): Object detections to annotate.
            custom_color_lookup (Optional[np.ndarray]): Custom color lookup array.
                Allows to override the default color mapping strategy.
        Returns:
            np.ndarray: The annotated image.

Review comment (suggestion):
I'd throw an exception here. This will be consistent with the behavior of other annotators when they do not receive basic configuration data.

Code after:
    def __init__(self, pixel_size: int = 20):
        """
        Args:
            pixel_size (int): The size of the pixelation.
        """
        self.pixel_size: int = pixel_size

    @ensure_cv2_image_for_annotation
    def annotate(
        self,
        scene: ImageType,
        detections: Detections,
    ) -> ImageType:
        """
        Annotates the given scene by pixelating regions based on the provided
            detections.

        Args:
            scene (ImageType): The image where pixelating will be applied.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections (Detections): Object detections to annotate.

        Returns:
            The annotated image, matching the type of `scene` (`numpy.ndarray`
                or `PIL.Image.Image`)

        Example:
            ```python
            import supervision as sv

            image = ...
            detections = sv.Detections(...)

            pixelate_annotator = sv.PixelateAnnotator()
            annotated_frame = pixelate_annotator.annotate(
                scene=image.copy(),
                detections=detections
            )
            ```

        ![pixelate-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/pixelate-annotator-example-10.png)
        """
        image_height, image_width = scene.shape[:2]
        clipped_xyxy = clip_boxes(
            xyxy=detections.xyxy, resolution_wh=(image_width, image_height)
        ).astype(int)

        for x1, y1, x2, y2 in clipped_xyxy:
            roi = scene[y1:y2, x1:x2]