
    ^j                      d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
Z
d dlZd dlmZ d dlmZmZ d dlmZmZmZ d dlmZmZ d d	lmZ d d
lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z;m<Z<m=Z= d dl>m?Z?m@Z@mAZA d dlBmCZCmDZD d dlEmFZFmGZGmHZHmIZI d dlJmKZK  eKeL      ZMe	dKd       ZNe		 	 	 	 dLd       ZNdLdZNe
j                  ZP G d de      ZQ G d de      ZR G d de      ZS	 dM	 	 	 	 	 	 	 	 	 	 	 dNd ZT G d! d"e      ZU G d# d$e      ZV G d% d&e      ZW G d' d(e      ZX G d) d*e      ZY G d+ d,e      ZZ G d- d.e      Z[ G d/ d0e      Z\ G d1 d2eQ      Z] G d3 d4eQ      Z^ G d5 d6e      Z_ G d7 d8e      Z` G d9 d:e      Za G d; d<e      Zb G d= d>e      Zc G d? d@e      Zd G dA dBe      Ze G dC dDe      Zf G dE dFe      Zg G dG dHe      Zh G dI dJ      Ziy)O    )annotations)	lru_cache)sqrt)AnycastoverloadN)
deprecatedvoid)Image	ImageDraw	ImageFont)splevsplprep)BaseAnnotator)PENDING_TRACK_IDColorLookupTrace_validate_labelscalculate_dynamic_kernel_sizecalculate_dynamic_pixel_sizeget_labels_texthex_to_rgbaresolve_colorresolve_text_background_xyxy
snap_boxes	wrap_text)ORIENTED_BOX_COORDINATES)CompactMask)
Detections)
clip_boxesspread_out_boxes)mask_to_polygonspolygon_to_maskxyxy_to_polygons)	ImageType)ColorColorPalette)draw_polygondraw_rounded_rectangle	draw_text)PointPositionRect)!ensure_cv2_image_for_class_method!ensure_pil_image_for_class_method)
crop_imageletterbox_imageoverlay_imagescale_image)_get_loggerc                     y N colors    f/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/annotators/core.py_normalize_color_inputr;   9   s    9<    c                     y r6   r7   r8   s    r:   r;   r;   =   s     r<   c                v    t        | t              r(t        |       \  }}}}t        j                  |||f      S | S )a  Normalize accepted color inputs to internal color objects.

    Accepts `Color`, `ColorPalette`, or hex string input. Hex strings are parsed via
    `hex_to_rgba` and converted to `Color` (alpha channel is ignored because annotator
    drawing uses RGB/BGR colors).
    )
isinstancestrr   r&   from_rgb_tuple)r9   rgb_s        r:   r;   r;   C   s<     % '
1a##Q1I..Lr<   c            	          e Zd ZdZej
                  ej                  ej                  de
j                  ddddf		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	dZ	 	 	 	 	 	 	 	 d
dZy)_BaseLabelAnnotatora  
    Base class for annotators that add labels to detections.

    Attributes:
        color: The color to use for the label background.
        color_lookup: The method used to determine the color of the label.
        text_color: The color to use for the label text.
        text_padding: The padding around the label text, in pixels.
        text_anchor: The position of the text relative to the detection
            bounding box.
        text_offset: A tuple of 2D coordinates `(x, y)` to
            offset the text position from the anchor point, in pixels.
        border_radius: The radius of the label background corners, in pixels.
        smart_position: Whether to intelligently adjust the label position to
            avoid overlapping with other elements.
        max_line_length: Maximum number of characters per line before
            wrapping the text. None means no wrapping.
    
   r   r   r   FNc
                    t        |      | _        || _        t        |      | _        || _        || _        || _        || _        || _        |	| _	        y)a  
        Initializes the _BaseLabelAnnotator.

        Args:
            color: The color to use for the label
                background.
            color_lookup: The method used to determine the color
                of the label
            text_color: The color to use for the
                label text.
            text_padding: The padding around the label text, in pixels.
            text_position: The position of the text relative to the
                detection bounding box.
            text_offset: A tuple of 2D coordinates
                `(x, y)` to offset the text position from the anchor point, in pixels.
            border_radius: The radius of the label background corners,
                in pixels.
            smart_position: Whether to intelligently adjust the label
                position to avoid overlapping with other elements.
            max_line_length: Maximum number of characters per
                line before wrapping the text. None means no wrapping.
        N)
r;   r9   color_lookup
text_colortext_paddingtext_anchortext_offsetborder_radiussmart_positionmax_line_length)
selfr9   rK   rL   rM   text_positionrO   rP   rQ   rR   s
             r:   __init__z_BaseLabelAnnotator.__init__g   sV    D ,B%+H
)50Fz0R!-%2,7"/,+:r<   c                    |j                         }t        |ddddf   |      |ddddf<   t        |      dkD  r?|ddddf   }t        |      }||ddddf<   t        |ddddf   |      |ddddf<   |S )a  
        Adjusts the position of labels to ensure they stay within the frame boundaries.

        Args:
            resolution_wh: The width and height of the frame.
            labels: The list of text labels.
            label_properties: An array of label properties, where each row
                            contains [x1, y1, x2, y2, text_height, ...].

        Returns:
            The adjusted label properties.
        N      )copyr   lenr!   )rS   resolution_whlabelslabel_propertiesadjusted_propertiesboxesspread_boxess          r:   _adjust_labels_in_framez+_BaseLabelAnnotator._adjust_labels_in_frame   s    $ /335 &02A2&&
ArrE" v;?'2A2.E+E2L)52A2& *4#ArrE*M*2A2& #"r<   )r9   Color | ColorPalette | strrK   r   rL   rb   rM   intrT   r,   rO   tuple[int, int]rP   rc   rQ   boolrR   
int | None)r[   rd   r\   	list[str]r]   npt.NDArray[np.float32]returnnpt.NDArray[np.uint8])__name__
__module____qualname____doc__r'   DEFAULTr   CLASSr&   WHITEr,   TOP_LEFTrU   ra   r7   r<   r:   rG   rG   S   s    * -9,@,@$/$5$516"*"3"3'-$&**;)*; "*; /	*;
 *;  *; %*; *; *; $*;X(#&(# (# 2	(#
 
(#r<   rG   c                  v    e Zd ZdZej
                  dej                  f	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 dd       Z
y)	BoxAnnotatorzS
    A class for drawing bounding boxes on an image using provided detections.
       c                @    t        |      | _        || _        || _        ya0  
        Args:
            color: The color or color palette to use for
                annotating detections.
            thickness: Thickness of the bounding box lines.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        Nr;   r9   	thicknessrK   rS   r9   ry   rK   s       r:   rU   zBoxAnnotator.__init__         ,B%+H
')5r<   Nc                x   t        |t        j                        s|S t        t	        |            D ]  }|j
                  |   j                  t              \  }}}}t        | j                  |||| j                  n|      }	t        j                  |||f||f|	j                         | j                          |S )a7  
        Annotates the given scene with bounding boxes based on the provided detections.

        Args:
            scene: The image where bounding boxes will be drawn. `ImageType`
                is a flexible type, accepting either `numpy.ndarray` or
                `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> box_annotator = sv.BoxAnnotator()
            >>> annotated_frame = box_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![bounding-box-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/bounding-box-annotator-example-purple.png)
        r9   
detectionsdetection_idxrK   imgpt1pt2r9   ry   )r?   npndarrayrangerZ   xyxyastyperc   r   r9   rK   cv2	rectangleas_bgrry   )
rS   scener~   custom_color_lookupr   x1y1x2y2r9   s
             r:   annotatezBoxAnnotator.annotate   s    T %,L"3z?3 	M'__];BB3GNBB!jj%+&. "..(E MMHHlln..	" r<   r9   rb   ry   rc   rK   r   r6   r   r%   r~   r   r   npt.NDArray[np.int_] | Noneri   r%   rk   rl   rm   rn   r'   ro   r   rp   rU   r.   r   r7   r<   r:   rt   rt           -9,@,@$/$5$5	6)6 6 "	6$ '
 <@	<< < 9	<
 
< '<r<   rt   c                  v    e Zd ZdZej
                  dej                  f	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 dd       Z
y)	OrientedBoxAnnotatorz\
    A class for drawing oriented bounding boxes on an image using provided detections.
    ru   c                @    t        |      | _        || _        || _        yrw   rx   rz   s       r:   rU   zOrientedBoxAnnotator.__init__  r{   r<   Nc                   t        |t        j                        s|S |j                  t        |j                  vr|S t        j
                  |j                  t                 j                  t              }t        t        |            D ]`  }||   }t        | j                  |||| j                  n|      }t        j                  ||gd|j                         | j                          b |S )a  
        Annotates the given scene with oriented bounding boxes based on the
        provided detections.

        Args:
            scene: The image where bounding boxes will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Example:
            ```python
            import cv2
            import supervision as sv
            from ultralytics import YOLO

            image = cv2.imread("<SOURCE_IMAGE_PATH>")
            model = YOLO("yolov8n-obb.pt")

            result = model(image)[0]
            detections = sv.Detections.from_ultralytics(result)

            oriented_box_annotator = sv.OrientedBoxAnnotator()
            annotated_frame = oriented_box_annotator.annotate(
                scene=image.copy(),
                detections=detections
            )
            ```
        r}   r   )r?   r   r   datar   arrayr   rc   r   rZ   r   r9   rK   r   drawContoursr   ry   )rS   r   r~   r   	obb_boxesr   obbr9   s           r:   r   zOrientedBoxAnnotator.annotate,  s    T %,L??"&>joo&ULHHZ__-EFGNNsS	"3z?3 	NMM*C!jj%+&. "..(E USE1ellndnnM	N r<   r   r6   r   r   r7   r<   r:   r   r     r   r<   r   c                   |j                   }|y|r(t        j                  | j                  dd t              nd}t        |t              r|nd}t        j                  t        j                  |j                              D ]  }t        ||||      j                         }	|t        |j                  |df         }
t        |j                  |df         }|j                  |      }|j                  \  }}|	| |||z   |
|
|z   f   |<   |||||z   |
|
|z   fxx   |z  cc<   t        j                  ||   t              }|	| |<   |||z  } |S )aE  Paint each detection's mask into `canvas` in descending-area order.

    Smaller masks are drawn on top of larger ones. `CompactMask` detections
    are painted into their bounding-box crop only, avoiding a full `(H, W)`
    allocation per mask; dense masks fall back to full-frame boolean indexing.

    Args:
        canvas: BGR image array painted in place. Shape ``(H, W, 3)``.
        detections: Detections whose masks to paint. Returns immediately
            without modifying `canvas` when ``detections.mask`` is ``None``.
        color: Single color or palette used to resolve each detection's color.
        color_lookup: Strategy for mapping colors to detection indices.
        collect_union: When ``True``, allocate and return a ``(H, W)``
            boolean array that accumulates the union of all painted masks
            (useful for callers like `HaloAnnotator` that need the combined
            mask footprint). When ``False`` (default), returns ``None``.

    Returns:
        A ``(H, W)`` boolean union array when ``collect_union=True``,
        otherwise ``None``.
    Nru   dtyper}   r   rX   )maskr   zerosshapere   r?   r   flipargsortarear   r   rc   offsetscropasarray)canvasr~   r9   rK   collect_unionmasksunioncompact_maskr   	color_bgrr   r   crop_mcrop_hcrop_wr   s                   r:   _paint_masks_by_arear   m  sp   8 OOE}2?bq!.T 
 'uk:5LJOO!<= !!'%	

 &( 	 #\))-*:;<B\))-*:;<B!&&}5F#\\NFFAJF2V#R"v+%556v> b2;&R&[(889VC9::eM2$?D$F4L '( Lr<   c                  v    e Zd ZdZej
                  dej                  f	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 dd       Z
y)	MaskAnnotatorz
    A class for drawing masks on an image using provided detections.

    !!! warning

        This annotator uses `sv.Detections.mask`.
          ?c                @    t        |      | _        || _        || _        yaC  
        Args:
            color: The color or color palette to use for
                annotating detections.
            opacity: Opacity of the overlay mask. Must be between `0` and `1`.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        N)r;   r9   opacityrK   rS   r9   r   rK   s       r:   rU   zMaskAnnotator.__init__  s      ,B%+H
)5r<   Nc                V   t        |t        j                        s|S |j                  |S t        j                  |dt        j
                        }t        ||| j                  || j                  n|       t        j                  || j                  |d| j                  z
  d|       |S )aV  
        Annotates the given scene with masks based on the provided detections.

        Args:
            scene: The image where masks will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     mask=np.zeros((1, 100, 100), dtype=bool),
            ...     class_id=np.array([0])
            ... )
            >>> mask_annotator = sv.MaskAnnotator()
            >>> annotated_frame = mask_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![mask-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/mask-annotator-example-purple.png)
        T)rY   r   rX   r   dst)r?   r   r   r   r   uint8r   r9   rK   r   addWeightedr   )rS   r   r~   r   colored_masks        r:   r   zMaskAnnotator.annotate  s    V %,L??"LxxDAJJ!4!<DBU		
 	$,,q4<</?	
 r<   r9   rb   r   floatrK   r   r6   r   r   r7   r<   r:   r   r     s     -9,@,@$/$5$5	6)6 6 "	6$ '
 <@	99 9 9	9
 
9 '9r<   r   c                  v    e Zd ZdZej
                  dej                  f	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 dd       Z
y)	PolygonAnnotatorz
    A class for drawing polygons on an image using provided detections.

    !!! warning

        This annotator uses `sv.Detections.mask`.
    ru   c                @    t        |      | _        || _        || _        y)a+  
        Args:
            color: The color or color palette to use for
                annotating detections.
            thickness: Thickness of the polygon lines.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        Nrx   rz   s       r:   rU   zPolygonAnnotator.__init__  r{   r<   Nc                L   t        |t        j                        s|S |j                  |S t	        t        |            D ]b  }|j                  |   }t        | j                  |||| j                  n|      }t        |      D ]  }t        |||| j                        } d |S )a-  
        Annotates the given scene with polygons based on the provided detections.

        Args:
            scene: The image where polygons will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> polygon_annotator = sv.PolygonAnnotator()
            >>> annotated_frame = polygon_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![polygon-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/polygon-annotator-example-purple.png)
        r}   )r   )r   polygonr9   ry   )r?   r   r   r   r   rZ   r   r9   rK   r"   r(   ry   )rS   r   r~   r   r   r   r9   r   s           r:   r   zPolygonAnnotator.annotate  s    T %,L??"L"3z?3 	M??=1D!jj%+&. "..(E ,6 $#"nn		$ r<   r   r6   r   r   r7   r<   r:   r   r     s     -9,@,@$/$5$5	6)6 6 "	6$ '
 <@	@@ @ 9	@
 
@ '@r<   r   c                  v    e Zd ZdZej
                  dej                  f	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 dd       Z
y)	ColorAnnotatorzN
    A class for drawing box masks on an image using provided detections.
    r   c                @    t        |      | _        || _        || _        yr   )r;   r9   rK   r   r   s       r:   rU   zColorAnnotator.__init__c  s      ,B%+H
)5r<   Nc                   t        |t        j                        s|S |j                         }t	        t        |            D ]|  }|j                  |   j                  t              \  }}}}	t        | j                  |||| j                  n|      }
t        j                  |||f||	f|
j                         d       ~ t        j                  || j                   |d| j                   z
  d|       |S )a0  
        Annotates the given scene with box masks based on the provided detections.

        Args:
            scene: The image where bounding boxes will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> color_annotator = sv.ColorAnnotator()
            >>> annotated_frame = color_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![box-mask-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/box-mask-annotator-example-purple.png)
        r}   r   rX   r   )gammar   )r?   r   r   rY   r   rZ   r   r   rc   r   r9   rK   r   r   r   r   r   )rS   r   r~   r   scene_with_boxesr   r   r   r   r   r9   s              r:   r   zColorAnnotator.annotateu  s    T %,L ::<"3z?3 	M'__];BB3GNBB!jj%+&. "..(E MM$HHlln	$ 	dllE1t||3C1RW	
 r<   r   r6   r   r   r7   r<   r:   r   r   ^  s     -9,@,@$/$5$5	)  "	$ '
 <@	AA A 9	A
 
A 'Ar<   r   c                  |    e Zd ZdZej
                  ddej                  f	 	 	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 d	d       Z
y)
HaloAnnotatorz
    A class for drawing Halos on an image using provided detections.

    !!! warning

        This annotator uses `sv.Detections.mask`.
    g?(   c                N    t        |      | _        || _        || _        || _        y)a  
        Args:
            color: The color or color palette to use for
                annotating detections.
            opacity: Opacity of the overlay mask. Must be between `0` and `1`.
            kernel_size: The size of the average pooling kernel used for creating
                the halo.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        N)r;   r9   r   rK   kernel_size)rS   r9   r   r   rK   s        r:   rU   zHaloAnnotator.__init__  s(    " ,B%+H
)5 +r<   Nc                   t        |t        j                        s|S |j                  |S t        j                  |t        j
                        }t        ||| j                  || j                  n|d      }|J t        j                  || j                  | j                  f      }g d||<   t        j                  |t        j                        }|j                         }|dk(  r|S | j                  |z  |z  }|ddddt        j                   f   }	t        j
                  |d|	z
  z  || j                  z  z         }
t        j"                  ||
       |S )ab  
        Annotates the given scene with halos based on the provided detections.

        Args:
            scene: The image where the halo effect will be applied.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     mask=np.zeros((1, 100, 100), dtype=bool),
            ...     class_id=np.array([0])
            ... )
            >>> halo_annotator = sv.HaloAnnotator()
            >>> annotated_frame = halo_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![halo-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/halo-annotator-example-purple.png)
        Nr   T)r   )r   r   r   r   rX   )r?   r   r   r   
zeros_liker   r   r9   rK   r   blurr   cvtColorCOLOR_BGR2GRAYmaxr   newaxiscopyto)rS   r   r~   r   r   fmaskgraygray_maxalpha
alpha_maskblended_scenes              r:   r   zHaloAnnotator.annotate  s,   V %,L??"L}}U"((;$JJ!4!<DBU
    xxt/?/?AQAQ.RS'U||L#*<*<=88:q=Lt#h.1a+,
!j.!9L4<<<W!WX
		%'r<   )r9   rb   r   r   r   rc   rK   r   r6   r   r   r7   r<   r:   r   r     s     -9,@,@$/$5$5,), , 	,
 ",, '
 <@	CC C 9	C
 
C 'Cr<   r   c                      e Zd ZdZej
                  dddej                  f	 	 	 	 	 	 	 	 	 ddZe		 d		 	 	 	 	 	 	 d
d       Z
y)EllipseAnnotatorzM
    A class for drawing ellipses on an image using provided detections.
    ru   i   c                \    t        |      | _        || _        || _        || _        || _        y)a  
        Args:
            color: The color or color palette to use for
                annotating detections.
            thickness: Thickness of the ellipse lines.
            start_angle: Starting angle of the ellipse.
            end_angle: Ending angle of the ellipse.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        N)r;   r9   ry   start_angle	end_anglerK   )rS   r9   ry   r   r   rK   s         r:   rU   zEllipseAnnotator.__init__%  s/    $ ,B%+H
' +')5r<   Nc                   t        |t        j                        s|S t        t	        |            D ]  }|j
                  |   j                  t              \  }}}}t        | j                  |||| j                  n|      }	t        ||z   dz        |f}
||z
  }t        j                  ||
t        |      t        d|z        fd| j                  | j                  |	j                         | j                   t        j"                  	        |S )a-  
        Annotates the given scene with ellipses based on the provided detections.

        Args:
            scene: The image where ellipses will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> ellipse_annotator = sv.EllipseAnnotator()
            >>> annotated_frame = ellipse_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![ellipse-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/ellipse-annotator-example-purple.png)
        r}   ru   gffffff?        )centeraxesangle
startAngleendAngler9   ry   lineType)r?   r   r   r   rZ   r   r   rc   r   r9   rK   r   ellipser   r   r   ry   LINE_4)rS   r   r~   r   r   r   _y1r   r   r9   r   widths               r:   r   zEllipseAnnotator.annotate=  s    T %,L"3z?3 	M(oom<CCCHOBR!jj%+&. "..(E 27a-("-FGEKK%j#dUl"34++lln..
	. r<   )
r9   rb   ry   rc   r   rc   r   rc   rK   r   r6   r   r   r7   r<   r:   r   r      s     -9,@,@$/$5$56)6 6 	6
 6 "60 '
 <@	BB B 9	B
 
B 'Br<   r   c                  |    e Zd ZdZej
                  ddej                  f	 	 	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 d	d       Z
y)
BoxCornerAnnotatorzP
    A class for drawing box corners on an image using provided detections.
    rW      c                N    t        |      | _        || _        || _        || _        y)aa  
        Args:
            color: The color or color palette to use for
                annotating detections.
            thickness: Thickness of the corner lines.
            corner_length: Length of each corner line.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        N)r;   r9   ry   corner_lengthrK   )rS   r9   ry   r   rK   s        r:   rU   zBoxCornerAnnotator.__init__  s(      ,B%+H
'"/)5r<   Nc           	        t        |t        j                        s|S t        t	        |            D ]  }|j
                  |   j                  t              \  }}}}t        | j                  |||| j                  n|      }	||f||f||f||fg}
|
D ]  \  }}||k(  r|| j                  z   n|| j                  z
  }t        j                  |||f||f|	j                         | j                         ||k(  r|| j                  z   n|| j                  z
  }t        j                  |||f||f|	j                         | j                           |S )a9  
        Annotates the given scene with box corners based on the provided detections.

        Args:
            scene: The image where box corners will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> corner_annotator = sv.BoxCornerAnnotator()
            >>> annotated_frame = corner_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![box-corner-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/box-corner-annotator-example-purple.png)
        r}   ry   )r?   r   r   r   rZ   r   r   rc   r   r9   rK   r   r   liner   ry   )rS   r   r~   r   r   r   r   r   r   r9   cornersxyx_endy_ends                  r:   r   zBoxCornerAnnotator.annotate  sP   T %,L"3z?3 	M'__];BB3GNBB!jj%+&. "..(E Bx"bB8b"X>G 	123r'D...q4CUCU?UAq6E1:u||~ 34r'D...q4CUCU?UAq6Au:u||~		, r<   )r9   rb   ry   rc   r   rc   rK   r   r6   r   r   r7   r<   r:   r   r     s     -9,@,@$/$5$56)6 6 	6
 "6* '
 <@	AA A 9	A
 
A 'Ar<   r   c                  v    e Zd ZdZej
                  dej                  f	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 dd       Z
y)	CircleAnnotatorzK
    A class for drawing circle on an image using provided detections.
    ru   c                @    t        |      | _        || _        || _        y)a)  
        Args:
            color: The color or color palette to use for
                annotating detections.
            thickness: Thickness of the circle line.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        Nrx   rz   s       r:   rU   zCircleAnnotator.__init__  s      ,B%+H
')5r<   Nc                   t        |t        j                        s|S t        t	        |            D ]  }|j
                  |   j                  t              \  }}}}||z   dz  ||z   dz  f}	t        ||	d   z
  dz  ||	d   z
  dz  z         }
t        | j                  |||| j                  n|      }t        j                  ||	t        |
      |j                         | j                          |S )a+  
        Annotates the given scene with circles based on the provided detections.

        Args:
            scene: The image where box corners will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> circle_annotator = sv.CircleAnnotator()
            >>> annotated_frame = circle_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```


        ![circle-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/circle-annotator-example-purple.png)
        ru   r   rX   r}   r   r   radiusr9   ry   )r?   r   r   r   rZ   r   r   rc   r   r   r9   rK   r   circler   ry   )rS   r   r~   r   r   r   r   r   r   r   distancer9   s               r:   r   zCircleAnnotator.annotate  s    V %,L"3z?3 	M'__];BB3GNBBBw1nrBw1n5FR&)^1R&)^4IIJH!jj%+&. "..(E JJ8}lln..	( r<   r   r6   r   r   r7   r<   r:   r  r    s     -9,@,@$/$5$5	6)6 6 "	6& '
 <@	@@ @ 9	@
 
@ '@r<   r  c                      e Zd ZdZej
                  dej                  ej                  de
j                  f	 	 	 	 	 	 	 	 	 	 	 ddZe	 d	 	 	 	 	 	 	 d	d       Zy)
DotAnnotatorzh
    A class for drawing dots on an image at specific coordinates based on provided
    detections.
    rW   r   c                |    t        |      | _        || _        || _        || _        || _        t        |      | _        y)aW  
        Args:
            color: The color or color palette to use for
                annotating detections.
            radius: Radius of the drawn dots.
            position: The anchor position for placing the dot.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
            outline_thickness: Thickness of the outline of the dot.
            outline_color: The color or color palette to
                use for outline. It is activated by setting outline_thickness to a value
                greater than 0.
        N)r;   r9   r	  positionrK   outline_thicknessoutline_color)rS   r9   r	  r  rK   r  r  s          r:   rU   zDotAnnotator.__init__D  s<    , ,B%+H
!"*)5!23I-3Xr<   Nc                v   t        |t        j                        s|S |j                  | j                        }t        t        |            D ]  }t        | j                  |||| j                  n|      }t        ||df         t        ||df         f}t        j                  ||| j                  |j                         d       | j                  st        | j                   |||| j                  n|      }t        j                  ||| j                  |j                         | j                          |S )a  
        Annotates the given scene with dots based on the provided detections.

        Args:
            scene: The image where dots will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> dot_annotator = sv.DotAnnotator()
            >>> annotated_frame = dot_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![dot-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/dot-annotator-example-purple.png)
        anchorr}   r   rX   r   )r?   r   r   get_anchors_coordinatesr  r   rZ   r   r9   rK   rc   r   r
  r	  r   r  r  )	rS   r   r~   r   xyr   r9   r   r  s	            r:   r   zDotAnnotator.annotatea  s'   T %,L//t}}/E"3z?3 	M!jj%+&. "..(E "]A-./Rq8H5I1JKFJJufdkk5<<>2F%% -,,)"/*2 "&!2!2,! 

KK!((***+	8 r<   )r9   rb   r	  rc   r  r,   rK   r   r  rc   r  rb   r6   r   )rk   rl   rm   rn   r'   ro   r,   CENTERr   rp   r&   BLACKrU   r.   r   r7   r<   r:   r  r  >  s     -9,@,@%__$/$5$5!"49KKY)Y Y 	Y
 "Y Y 2Y: '
 <@	HH H 9	H
 
H 'Hr<   r  c                  :    e Zd ZdZej
                  ej                  ej                  ddde
j                  ddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Ze	 	 d	 	 	 	 	 	 	 	 	 dd
       Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 ddZe	 	 	 	 	 	 	 	 	 	 dd       Z xZS )LabelAnnotatorzN
    A class for annotating labels on an image using provided detections.
    r   rX   rH   rI   r   FNc                R    || _         || _        t        |   |||||||	|
|	       y)a  
        Args:
            color: The color or color palette to use for
                annotating the text background.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
            text_color: The color or color palette to use
                for the text.
            text_scale: Font scale for the text.
            text_thickness: Thickness of the text characters.
            text_padding: Padding around the text within its background box.
            text_position: Position of the text relative to the detection.
                Possible values are defined in the `Position` enum.
            text_offset: A tuple of 2D coordinates `(x, y)` to
                offset the text position from the anchor point, in pixels.
            border_radius: The radius to apply round edges. If the selected
                value is higher than the lower dimension, width or height, is clipped.
            smart_position: Spread out the labels to avoid overlapping.
            max_line_length: Maximum number of characters per line
                before wrapping the text. None means no wrapping.
        	r9   rK   rL   rM   rT   rO   rP   rQ   rR   N)
text_scaletext_thicknesssuperrU   )rS   r9   rK   rL   r  r  rM   rT   rO   rP   rQ   rR   	__class__s               r:   rU   zLabelAnnotator.__init__  sB    F ",#1%!%'#')+ 	 
	
r<   c                v   t        |t        j                        s|S t        ||       t	        ||      }| j                  ||      }| j                  rP|ddddf   }t        |      }||ddddf<   | j                  |j                  d   |j                  d   f||      }| j                  |||||       |S )a  
        Annotates the given scene with labels based on the provided detections.

        Args:
            scene: The image where labels will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            labels: Custom labels for each detection.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     confidence=np.array([0.9]),
            ...     class_id=np.array([0]),
            ...     data={'class_name': np.array(['person'])}
            ... )
            >>> labels = [
            ...     f"{class_name} {confidence:.2f}"
            ...     for class_name, confidence
            ...     in zip(detections['class_name'], detections.confidence)
            ... ]
            >>> label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)
            >>> annotated_frame = label_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections,
            ...     labels=labels
            ... )

            ```

        ![label-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/label-annotator-example-purple.png)
        NrW   rX   r   )r   r\   r]   r~   r   )r?   r   r   r   r   _get_label_propertiesrQ   r!   ra   r   _draw_labels)rS   r   r~   r\   r   r]   r   s          r:   r   zLabelAnnotator.annotate  s    h %,L, V4484N4N5
 #ArrE*D#D)D&*QU##;;QQ0   	-! 3 	 	
 r<   c                T   g }|j                  | j                        j                  t              }t	        ||      D ]3  \  }}|d   | j
                  d   z   |d   | j
                  d   z   f}t        || j                        }g }g }	|D ][  }
t        j                  |
t        | j                  | j                        d   \  }}|j                  |       |	j                  |       ] |	rt        |	      nd}t        |      t!        |      dz
  | j"                  z  z   }|d| j"                  z  z   }|d| j"                  z  z   }t%        |||f| j                        }|j                  g ||       6 t'        j(                  |t&        j*                        j-                  dd	      S )
Nr  r   rX   textfontFace	fontScalery   ru   center_coordinatestext_whr  r   r      )r  rN   r   rc   ziprO   r   rR   r   getTextSizeCV2_FONTr  r  appendr   sumrZ   rM   r   r   r   float32reshape)rS   r~   r\   r]   anchors_coordinateslabelr*  wrapped_linesline_heightsline_widthsr   text_wtext_h	max_widthtotal_heightwidth_paddedheight_paddedtext_background_xyxys                     r:   r"  z$LabelAnnotator._get_label_properties5  s   
 5?5W5W## 6X 6

&+ 	 *-V5H)I )	%E%"1%(8(8(;;"1%(8(8(;;"
 &eT-A-ABMLK% +#&??%"oo"11	$
 $  ##F+""6*+ -8K(QIL!S%6%:d>O>O$OO 
 %q4+<+<'<<L(1t/@/@+@@M#?#5%}5))$  ##) I)	T xx(

;CCBJJr<   c                J   t        |      t        |      cxk(  rt        |      k(  s.n J dt        |       dt        |       dt        |       d       ||n| j                  }t        |      D ]  \  }}t        | j                  |||      }	t        | j
                  |||      }
|d d j                  t              }| j                  |||	j                         | j                         t        ||   | j                        }|d   | j                  z   }|D ]  }|sJt        j                  d	t         | j"                  | j$                  
      d   \  }}||| j                  z   z  }Pt        j                  |t         | j"                  | j$                  
      d   \  }}|d   | j                  z   }||z   }t        j&                  ||||ft         | j"                  |
j                         | j$                  t        j(                         ||| j                  z   z  }  y )NNumber of label properties (), labels () and detections () do not match.r}   rW   )r   r   r9   rP   rX   Tgr%  r   )r   r&  orgr'  r(  r9   ry   r   )rZ   rK   	enumerater   r9   rL   r   rc   r)   r   rP   r   rR   rM   r   r.  r/  r  r  putTextLINE_AA)rS   r   r\   r]   r~   r   rK   idxlabel_propertybackground_colorrL   box_xyxyr6  	current_yr   rE   r:  text_xtext_ys                      r:   r#  zLabelAnnotator._draw_labelsk  sI    6{c"23Fs:F 	
*3/?+@*A B6{m#5c*o5F G	
F #.  "" 	 $--=#> <	8C,jj%!)	  'oo%!)	J &bq)005H''&--/"00	 (  &fSk43G3GHM d&7&77I% !8"%//!!)"&//"&"5"5	#
 #KQ $*;*;!;;I!oo%"oo"11	
 F "!t'8'88"V+(%"oo$++-"11 [[	 Vd&7&777	C!87<	8r<   c                n   |\  }}}}||z
  }||z
  }	t        |t        ||	      dz        }||z   |f||z
  |ff|||z   f|||z
  ffg}
||z   ||z   f||z
  ||z   f||z   ||z
  f||z
  ||z
  fg}|
D ]"  }t        j                  | |d   |d   |d       $ |D ]  }t        j                  | |||d        | S )Nru   r   rX   r   r   r  )minr   r   r
  )r   r   r9   rP   r   r   r   r   r   heightrectangle_coordinatescircle_centerscoordinatesr   s                 r:   r)   z%LabelAnnotator.draw_rounded_rectangle  s5    BBRbM3uf+=+BC = "%](:B'?@"}$%B,>'?@!

 -m!34-m!34-m!34-m!34	
 1 	KMMNN	 % 	FJJ$	 r<   )r9   rb   rK   r   rL   rb   r  r   r  rc   rM   rc   rT   r,   rO   rd   rP   rc   rQ   re   rR   rf   NN
r   Image.Imager~   r   r\   zlist[str] | Noner   r   ri   rY  )r~   r   r\   rg   ri   r   )r   rj   r\   rg   r]   rh   r~   r   r   r   ri   None)
r   rj   r   ztuple[int, int, int, int]r9   ztuple[int, int, int]rP   rc   ri   rj   )rk   rl   rm   rn   r'   ro   r   rp   r&   rq   r,   rr   rU   r.   r   r"  r#  staticmethodr)   __classcell__r   s   @r:   r  r    s    -9,@,@$/$5$516"*"3"3'-$&*/
)/
 "/
 /	/

 /
 /
 /
  /
 %/
 /
 /
 $/
b '
 $(;?OO O !	O
 9O 
O 'Ob4K4K 4K 
	4KlP8$P8 P8 2	P8
 P8 9P8 
P8d '$''' $' 	'
 
' 'r<   r  c                  6    e Zd ZdZej
                  ej                  ej                  ddde
j                  ddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZe	 	 d	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 	 	 dd	Z	 	 	 	 	 	 	 	 	 	 	 	 dd
Ze	 	 	 	 	 	 dd       Z xZS )RichLabelAnnotatorz
    A class for annotating labels on an image using provided detections,
    with support for Unicode characters by using a custom font.
    NrH   rI   r   Fc                    || _         || _        | j                  ||      | _        t        |   |||||||	|
|	       y)a  
        Args:
            color: The color or color palette to use for
                annotating the text background.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
            text_color: The color to use for the text.
            font_path: Path to the font file (e.g., ".ttf" or ".otf")
                to use for rendering text. If `None`, the default PIL font will be used.
            font_size: Font size for the text.
            text_padding: Padding around the text within its background box.
            text_position: Position of the text relative to the detection.
                Possible values are defined in the `Position` enum.
            text_offset: A tuple of 2D coordinates `(x, y)` to
                offset the text position from the anchor point, in pixels.
            border_radius: The radius to apply round edges. If the selected
                value is higher than the lower dimension, width or height, is clipped.
            smart_position: Spread out the labels to avoid overlapping.
            max_line_length: Maximum number of characters per line
                before wrapping the text. None means no wrapping.
        r  N)	font_path	font_size
_load_fontfontr  rU   )rS   r9   rK   rL   ra  rb  rM   rT   rO   rP   rQ   rR   r   s               r:   rU   zRichLabelAnnotator.__init__  sS    F #"OOIy9	%!%'#')+ 	 
	
r<   c                   t        |t        j                        sJ t        ||       t        j                  |      }t        ||      }| j                  |||      }| j                  rJ|ddddf   }t        |      }||ddddf<   | j                  |j                  |j                  f||      }| j                  |||||       |S )a  
        Annotates the given scene with labels based on the provided
        detections, with support for Unicode characters.

        Args:
            scene: The image where labels will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            labels: Custom labels for each detection.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> from PIL import Image
            >>> image = Image.fromarray(np.zeros((100, 100, 3), dtype=np.uint8))
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     confidence=np.array([0.9]),
            ...     class_id=np.array([0]),
            ...     data={'class_name': np.array(['person'])}
            ... )
            >>> labels = [
            ...     f"{class_name} {confidence:.2f}"
            ...     for class_name, confidence
            ...     in zip(detections['class_name'], detections.confidence)
            ... ]
            >>> rich_label_annotator = sv.RichLabelAnnotator()
            >>> annotated_frame = rich_label_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections,
            ...     labels=labels
            ... )

            ```
        NrW   )drawr\   r]   r~   r   )r?   r   r   r   Drawr   r"  rQ   r!   ra   r   rS  r#  )rS   r   r~   r\   r   rf  r]   r   s           r:   r   zRichLabelAnnotator.annotate   s    f %---,~~e$ V4484N4N*f5
 #ArrE*D#D)D&*QU##;;ell+   	-! 3 	 	
 r<   c                |   g }|j                  | j                        j                  t              }t	        ||      D ]E  \  }}|d   | j
                  d   z   |d   | j
                  d   z   f}t        || j                        }d}	d}
|D ]@  }|j                  d|| j                        \  }}}}||z
  }||z
  }t        |	|      }	|
|z  }
B t        |      dkD  r|
t        |      dz
  | j                  z  z  }
t        |	d| j                  z  z         }t        |
d| j                  z  z         }t        |||f| j                        }|j                  dd	| j                        \  }}}}|j                  g |||       H t        j                   |t        j"                  
      j%                  dd      }|S )Nr  r   rX   r   rI   rd  ru   r)  rE  r   r      )r  rN   r   rc   r-  rO   r   rR   textbboxrd  r   rZ   rM   r   r0  r   r   r2  r3  )rS   rf  r~   r\   r]   anchor_coordinatesr5  r*  r6  r;  r<  r   lefttoprightbottom
line_widthline_heightr=  r>  r?  	text_lefttext_toprE   results                            r:   r"  z(RichLabelAnnotator._get_label_propertiesq  s    4>4V4V## 5W 5

&+ 	 *-V5G)H $	R%E%"1%(8(8(;;"1%(8(8(;;"
 &eT-A-ABM IL% ,+/==DII=+V(c5&"T\
$sl	:6	+, =!A%]!3a!74;L;L LLy1t/@/@+@@ALq43D3D/D DEM#?#5%}5))$  )-fd(S%IxA##$P&:$PI$Px$PQI$	RL +-((BJJ+

'"a. 	 r<   c           	     p   t        |      t        |      cxk(  rt        |      k(  s.n J dt        |       dt        |       dt        |       d       ||n| j                  }t        |      D ]C  \  }}t        | j                  |||      }	t        | j
                  |||      }
|d d j                  t              }|d   }|d   }|j                  t        |      | j                  |	j                         d        t        ||   | j                        }|d	   | j                  z   |z
  }|d
   | j                  z   |z
  }|D ]k  }|j                  ||f|| j                   |
j                                |j#                  d|| j                         \  }}}}||z
  }||| j                  z   z  }m F y )NrA  rB  rC  rD  r}   rW   r,  )r	  filloutliner   rX   )r  r&  rd  rw  rI   ri  )rZ   rK   rG  r   r9   rL   r   rc   rounded_rectangletuplerP   as_rgbr   rR   rM   r&  rd  rk  )rS   rf  r\   r]   r~   r   rK   rJ  rK  rL  rL   rM  rs  rt  r6  
x_position
y_positionr   _leftrn  _rightrp  rr  s                          r:   r#  zRichLabelAnnotator._draw_labels  s    6{c"23Fs:F 	
*3/?+@*A B6{m#5c*o5F G	
F #.  "" 	 $--=#> *	>C,jj%!)	  'oo%!)	J &bq)005H&q)I%a(H ""h))%,,.	 #  &fSk43G3GHM!!t'8'889DJ!!t'8'888CJ% >		"J/#**,	   .2]]64dii]-X*sFF$slkD,=,===
>?*	>r<   c                    	 	 	 	 dd}| ||       S 	 t        j                  ||       S # t        $ r! t        j	                  d|        ||       cY S w xY w)Nc                t    	 t        j                  |       S # t        $ r t        j                         cY S w xY wr6   )r   load_default	TypeError)sizes    r:   load_default_fontz8RichLabelAnnotator._load_font.<locals>.load_default_font  s6    0 --d33 0 --//0s    77z3Font path '%s' not found. Using PIL's default font.)r  rc   ri   ,ImageFont.FreeTypeFont | ImageFont.ImageFont)r   truetypeOSErrorloggerwarning)rb  ra  r  s      r:   rc  zRichLabelAnnotator._load_font  so    	0	09	0 $Y//	0%%i;; 	0NNEy %Y//		0s   * 'AA)r9   rb   rK   r   rL   rb   ra  
str | Nonerb  rc   rM   rc   rT   r,   rO   rd   rP   rc   rQ   re   rR   rf   rW  rX  )rf  ImageDraw.ImageDrawr~   r   r\   rg   ri   r   )rf  r  r\   rg   r]   rh   r~   r   r   r   ri   rZ  )rb  rc   ra  r  ri   r  )rk   rl   rm   rn   r'   ro   r   rp   r&   rq   r,   rr   rU   r/   r   r"  r#  r[  rc  r\  r]  s   @r:   r_  r_    s    -9,@,@$/$5$516 $"*"3"3'-$&*0
)0
 "0
 /	0

 0
 0
 0
  0
 %0
 0
 0
 $0
d '
 $(;?NN N !	N
 9N 
N 'N`2'25?2IR2	2h=>!=> => 2	=>
 => 9=> 
=>~ 00#-0	50 0r<   r_  c                  t    e Zd ZdZdej
                  df	 	 	 	 	 ddZe	 d		 	 	 	 	 	 	 d
d       Ze	dd       Z
y)IconAnnotatorzM
    A class for drawing an icon on an image, using provided detections.
    )@   r  rI   c                .    || _         || _        || _        y)a\  
        Args:
            icon_resolution_wh: The size of drawn icons.
                All icons will be resized to this resolution, keeping the aspect ratio.
            icon_position: The position of the icon.
            offset_xy: The offset to apply to the icon position,
                in pixels. Can be both positive and negative.
        N)icon_resolution_whr  	offset_xy)rS   r  icon_positionr  s       r:   rU   zIconAnnotator.__init__  s     #5%"r<   c                   t        |t        j                        s|S t        |t              r;t	        |      t	        |      k7  r$t        dt	        |       dt	        |       d      |j                  | j                        j                  t              }t        t	        |            D ]  }t        |t              r|n||   }|dk(  r | j                  |      }|j                  dd \  }}	t        ||df   |	dz  z
  | j                  d   z         }
t        ||d	f   |dz  z
  | j                  d	   z         }t        |||
|f      |dd  |S )
a#  
        Annotates the given scene with given icons.

        Args:
            scene: The image where labels will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            icon_path: The path to the PNG image to use as an
                icon. Must be a single path or a list of paths, one for each detection.
                Pass an empty string `""` to draw nothing.

        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(...)

            available_icons = ["roboflow.png", "lenny.png"]
            icon_paths = [np.random.choice(available_icons) for _ in detections]

            icon_annotator = sv.IconAnnotator()
            annotated_frame = icon_annotator.annotate(
                scene=image.copy(),
                detections=detections,
                icon_path=icon_paths
            )
            ```

        ![icon-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/icon-annotator-example.png)
        z#The number of icon paths provided (z+) does not match the number of detections (z?). Either provide a single icon path or one for each detection.r   Nru   r   rX   )r?   r   r   listrZ   
ValueErrorr  r  r   rc   r   r@   
_load_iconr   r  r2   )rS   r   r~   	icon_pathr  r   current_pathiconicon_hicon_wr   r  s               r:   r   zIconAnnotator.annotate  sb   X %,Li&3y>S_+L5c)n5E F--0_,= >89  %/$F$F== %G %

&+ 	 #3z?3 	:M'	37	Y}=U  r!??<0D!ZZ^NFFB}a'(6A:5q8IIJAB}a'(6A:5q8IIJA$UD1a&9E!H	: r<   c                    t        j                  |t         j                        }|t        d|       t	        t
        j                  t        j                     t        || j                              }|S )Nz)Error: Couldn't load the icon image from )imager[   )r   imreadIMREAD_UNCHANGEDFileNotFoundErrorr   nptNDArrayr   r   r1   r  )rS   r  r  s      r:   r  zIconAnnotator._load_icon[  sg    zz)S%9%9:<#;I;G  KK!$d6M6MN
 r<   N)r  rd   r  r,   r  rd   )r  )r   r%   r~   r   r  zstr | list[str]ri   r%   )r  r@   ri   rj   )rk   rl   rm   rn   r,   
TOP_CENTERrU   r.   r   r   r  r7   r<   r:   r  r    s     /7"*"5"5%+	#+#  # #	#$ '
 &(	EE E #	E
 
E 'EN 
 
r<   r  c                  8    e Zd ZdZdddZe	 	 	 	 	 	 dd       Zy)BlurAnnotatorzM
    A class for blurring regions in an image using provided detections.
    Nc                >    ||dk  rt        d| d      || _        y)a  
        Args:
            kernel_size: The size of the average pooling kernel used for blurring.
                If not set, a dynamic size is computed as one-third of the shorter
                bounding-box dimension. Must be >= 1 when provided.
        NrX   zkernel_size must be >= 1, got .)r  r   )rS   r   s     r:   rU   zBlurAnnotator.__init__n  s-     "{Q=k]!LMM'2r<   c                   t        |t        j                        s|S |j                  dd \  }}t	        |j
                  ||f      j                  t              }|D ]f  \  }}}}	||k  s|	|k  r|||	||f   }
| j                  | j                  nt        ||||	      }t        j                  |
||f      }
|
|||	||f<   h |S )a  
        Annotates the given scene by blurring regions based on the provided detections.

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

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> blur_annotator = sv.BlurAnnotator()
            >>> annotated_frame = blur_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![blur-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/blur-annotator-example-purple.png)
        Nru   r   r[   )r?   r   r   r   r    r   r   rc   r   r   r   r   )rS   r   r~   image_heightimage_widthclipped_xyxyr   r   r   r   roir   s               r:   r   zBlurAnnotator.annotatey  s    N %,L$)KKO!k.8l0K/

&+ 	 + 
	&NBBRx282r"u%C ##/   22r2rB 
 ((3k :;C"%E"R%B,
	& r<   r6   )r   rf   r   r%   r~   r   ri   r%   rk   rl   rm   rn   rU   r.   r   r7   r<   r:   r  r  i  s<    	3 '99 9 
	9 '9r<   r  c                      e Zd ZdZej
                  ej                  dddej                  f	 	 	 	 	 	 	 	 	 	 	 ddZ
e	 d		 	 	 	 	 	 	 d
d       Zy)TraceAnnotatora  
    A class for drawing trace paths on an image based on detection coordinates.

    !!! warning

        This annotator uses the `sv.Detections.tracker_id`. Read
        [here](/latest/trackers/) to learn how to plug
        tracking into your inference pipeline.
       ru   Fc                r    t        |      | _        t        ||      | _        || _        || _        || _        y)a)  
        Args:
            color: The color to draw the trace, can be
                a single color or a color palette.
            position: The position of the trace.
                Defaults to `CENTER`.
            trace_length: The maximum length of the trace in terms of historical
                points. Defaults to `30`.
            thickness: The thickness of the trace lines. Defaults to `2`.
            smooth: If `True`, applies spline smoothing to trace lines using
                consecutive unique anchor points. Falls back to a raw polyline
                when fewer than 4 unique points are available (e.g. when a
                tracker is stationary).
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
        )max_sizer  N)r;   r9   r   tracery   smoothrK   )rS   r9   r  trace_lengthry   r  rK   s          r:   rU   zTraceAnnotator.__init__  s5    2 ,B%+H
LB
")5r<   Nc                   t        |t        j                        s|S |j                  t	        d      ||j                  t
        k7     }| j                  j                  |       t        t        |            D ]  }|j                  |   }|t        |      }t        | j                  |||| j                  n|      }| j                  j                  |      }	|	j                  t        j                         }
| j"                  r|	t        j$                  dgt        j&                  t        j(                  |	d      dk7  d      f         }t        |      d	kD  r{	 |dddf   |dddf   }}t+        ||gd
      \  }}t-        t        j.                  ddd      |      }t        j0                  |d      j                  t        j                         }
n|j                  t        j                         }
t        |	      dkD  st3        j4                  ||
gd|j7                         | j8                          |S # t        $ r" |j                  t        j                         }
Y rw xY w)a  
        Draws trace paths on the frame based on the detection coordinates provided.

        Args:
            scene: The image on which the traces will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: The detections which include coordinates for
                which the traces will be drawn.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Example:
            ```python
            import supervision as sv
            from ultralytics import YOLO

            model = YOLO('yolov8x.pt')
            trace_annotator = sv.TraceAnnotator()

            video_info = sv.VideoInfo.from_video_path(video_path='...')
            frames_generator = sv.get_video_frames_generator(source_path='...')
            tracker = sv.ByteTrack()

            with sv.VideoSink(target_path='...', video_info=video_info) as sink:
               for frame in frames_generator:
                   result = model(frame)[0]
                   detections = sv.Detections.from_ultralytics(result)
                   detections = tracker.update_with_detections(detections)
                   annotated_frame = trace_annotator.annotate(
                       scene=frame.copy(),
                       detections=detections)
                   sink.write_frame(frame=annotated_frame)
            ```

        ![trace-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/trace-annotator-example-purple.png)
        NzThe `tracker_id` field is missing in the provided detections. See more: https://supervision.roboflow.com/latest/how_to/track_objectsr}   )
tracker_idTr   )axisrX         )sd   F)r9   ry   )r?   r   r   r  r  r   r  putr   rZ   rc   r   r9   rK   getr   int32r  concatenateanydiffr   r   linspacestackr   	polylinesr   ry   )rS   r   r~   r   filtered_detectionsr   tracker_id_valr  r9   r  spline_points	unique_xyr   r  tck_uxy_news                    r:   r   zTraceAnnotator.annotate  s'   b %,L  (Z  +5!!%55+
 	

*+"3':#;< &	M0;;MJN%^,J!jj.+&. "..(E :6B3599RXX3FM{{NNTFBFF2772A3F!3KRS,T#UV	 y>A%C(A	!Q$1")1a&B"7R!&r{{1a'=s!C(*a(@(G(G(Q %.$4$4RXX$>M2w{"O,,."nnA&	N  & C(1(8(8(BCs   A9I  (I+*I+)r9   rb   r  r,   r  rc   ry   rc   r  re   rK   r   r6   r   )rk   rl   rm   rn   r'   ro   r,   r  r   rp   rU   r.   r   r7   r<   r:   r  r    s     -9,@,@%__$/$5$56)6 6 	6
 6 6 "6> '
 <@	cc c 9	c
 
c 'cr<   r  c                  b    e Zd ZdZej
                  dddddf	 	 	 	 	 	 	 	 	 	 	 d
dZedd       Zy	)HeatMapAnnotatorz
    A class for drawing heatmaps on an image based on provided detections.
    Heat accumulates over time and is drawn as a semi-transparent overlay
    of blurred circles.
    g?r      r   }   c                f    || _         || _        || _        || _        || _        || _        d| _        y)a  
        Args:
            position: The position of the heatmap. Defaults to
                `BOTTOM_CENTER`.
            opacity: Opacity of the overlay mask. Must be between `0` and `1`.
            radius: Radius of the heat circle.
            kernel_size: Kernel size for blurring the heatmap. Pass `None`
                to disable blurring entirely.
            top_hue: Hue at the top of the heatmap. Defaults to 0 (red).
            low_hue: Hue at the bottom of the heatmap. Defaults to 125 (blue).
        N)r  r   r	  r   top_huelow_hue	heat_mask)rS   r  r   r	  r   r  r  s          r:   rU   zHeatMapAnnotator.__init__N  s6    ( !&9=r<   c                   t        |t        j                        s|S | j                  7t        j                  |j
                  dd t        j                        | _        t        j                  |j
                  dd       }|j                  | j                        D ]D  }t        |d         t        |d         }}t        j                  |||f| j                  dd       F || j                  z   | _        | j                  j                         }|j                         }|dkD  r,| j                  ||z  | j                  | j                   z
  z  z
  }|j#                  t        j$                        }| j&                  ,t        j(                  || j&                  | j&                  f      }t        j*                  |j
                  d	t        j$                        }	||	d
<   t        j,                  |	t        j.                        }t        j,                  | j                  j#                  t        j$                        t        j0                        dkD  }t        j2                  || j4                  |d| j4                  z
  d      |   ||<   |S )aX  
        Annotates the scene with a heatmap based on the provided detections.

        Args:
            scene: The image where the heatmap will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.

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

        Note:
            When `detections` is empty or no heat has accumulated yet, the
            scene is returned unchanged without raising a ``RuntimeWarning``.

        Example:
            ```python
            import supervision as sv
            from ultralytics import YOLO

            model = YOLO('yolov8x.pt')

            heat_map_annotator = sv.HeatMapAnnotator()

            video_info = sv.VideoInfo.from_video_path(video_path='...')
            frames_generator = sv.get_video_frames_generator(source_path='...')

            with sv.VideoSink(target_path='...', video_info=video_info) as sink:
               for frame in frames_generator:
                   result = model(frame)[0]
                   detections = sv.Detections.from_ultralytics(result)
                   annotated_frame = heat_map_annotator.annotate(
                       scene=frame.copy(),
                       detections=detections)
                   sink.write_frame(frame=annotated_frame)
            ```

        ![heatmap-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/heat-map-annotator-example-purple.png)
        Nru   r   r   rX   )rX   r   r     ).r   )r?   r   r   r  r   r   r2  r  r  rc   r   r
  r	  rY   r   r  r  r   r   r   r   fullr   COLOR_HSV2BGRCOLOR_GRAY2BGRr   r   )
rS   r   r~   r   r  r   r  tempmax_valhsvs
             r:   r   zHeatMapAnnotator.annotatej  s   X %,L>>!XXekk"1oRZZHDNxxBQ(44T]]C 	Br!u:s2a5zqAJJ1v{{	 .~~""$((*Q;<<$.DLL4<<4O"PPD{{288$'88D4#3#3T5E5E"FGDggekk3bhh7F||C!2!23||DNN11"((;S=O=OPSTToodDLL%T\\AQSTU
d r<   N)r  r,   r   r   r	  rc   r   rf   r  rc   r  rc   r  )	rk   rl   rm   rn   r,   BOTTOM_CENTERrU   r.   r   r7   r<   r:   r  r  G  sv     &33"$>> > 	>
  > > >8 'I 'Ir<   r  c                  8    e Zd ZdZdddZe	 	 	 	 	 	 dd       Zy)PixelateAnnotatorzO
    A class for pixelating regions in an image using provided detections.
    Nc                >    ||dk  rt        d| d      || _        y)a  
        Args:
            pixel_size: The size of the pixelation. If not set, a dynamic size is
                computed as one-half of the shorter bounding-box dimension. When set
                and the detection area is smaller than `pixel_size`, the region is
                filled with its average colour instead to avoid an OpenCV crash.
                Must be >= 1 when provided.
        NrX   zpixel_size must be >= 1, got r  )r  
pixel_size)rS   r  s     r:   rU   zPixelateAnnotator.__init__  s,     !j1n<ZLJKK&0r<   c                V   t        |t        j                        s|S |j                  dd \  }}t	        |j
                  ||f      j                  t              }|D ]H  \  }}}}	||k  s|	|k  r|||	||f   }
| j                  | j                  nt        ||||	      }t        |	|z
  ||z
        |k  r|
j                  dk(  s!|
j                  dk(  r4|
j                  d   dk(  r"t        j                  |
      d   |||	||f<   n0|j                  d   }t        j                  |
      d| |||	||f<   t        j                  |
dd|z  d|z        }t        j                  ||
j                  d   |
j                  d   ft        j                        }||||	||f<   K |S )	a  
        Annotates the given scene by pixelating regions based on the provided
            detections.

        Args:
            scene: The image where pixelating will be applied.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            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)
        Nru   r  r  rX   r   )srcdsizefxfy)r  r  interpolation)r?   r   r   r   r    r   r   rc   r  r   rR  ndimr   meanresizeINTER_NEAREST)rS   r   r~   r  r  r  r   r   r   r   r  r  num_channelsscaled_up_roiscaled_down_rois                  r:   r   zPixelateAnnotator.annotate  s   J %,L$)KKO!k.8l0K/

&+ 	 + 	2NBBRx282r"u%C ??. 1"b"bA 
 27BG$z188q=SXX]syy|q7H*-((3-*:E"R%B,'#(;;q>L*-((3-*FE"R%B,'JJtJ1z>M "jj!yy|SYYq\2!//O #2E"R%B,7	2: r<   r6   )r  rf   r  r  r7   r<   r:   r  r    sA    1 'HH H 
	H 'Hr<   r  c                      e Zd ZdZej
                  ddej                  ej                  de
j                  f	 	 	 	 	 	 	 	 	 	 	 	 	 ddZe	 d	 	 	 	 	 	 	 d	d       Zy)
TriangleAnnotatorzt
    A class for drawing triangle markers on an image at specific coordinates based on
    provided detections.
    rH   r   c                    t        |      | _        || _        || _        || _        || _        || _        t        |      | _        y)a  
        Args:
            color: The color or color palette to use for
                annotating detections.
            base: The base width of the triangle.
            height: The height of the triangle.
            position: The anchor position for placing the triangle.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
            outline_thickness: Thickness of the outline of the triangle.
            outline_color: The color or color palette to
                use for outline. It is activated by setting outline_thickness to a value
                greater than 0.
        N)r;   r9   baserS  r  rK   r  r  )rS   r9   r  rS  r  rK   r  r  s           r:   rU   zTriangleAnnotator.__init__	  sC    0 ,B%+H
	!"*)5&73I-3Xr<   Nc                "   t        |t        j                        s|S |j                  | j                        }t        t        |            D ]>  }t        | j                  |||| j                  n|      }t        ||df         t        ||df         }}t        j                  || j                  dz  z
  || j                  z
  g|| j                  dz  z   || j                  z
  g||ggt        j                        }	t        j                   ||	g|j#                                | j$                  st        | j&                  |||| j                  n|      }
t        j(                  ||	gd|
j#                         | j$                         A |S )a-  
        Annotates the given scene with triangles based on the provided detections.

        Args:
            scene: The image where triangles will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> triangle_annotator = sv.TriangleAnnotator()
            >>> annotated_frame = triangle_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![triangle-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/triangle-annotator-example.png)
        r  r}   r   rX   ru   Tr   )r?   r   r   r  r  r   rZ   r   r9   rK   rc   r   r  rS  r  r   fillPolyr   r  r  r  )rS   r   r~   r   r  r   r9   tip_xtip_yverticesr  s              r:   r   zTriangleAnnotator.annotate;	  s   T %,L//t}}/E"3z?3 #	M!jj%+&. "..(E r-"234c"]A=M:N6O5ExxTYY!^+UT[[-@ATYY!^+UT[[-@AEN
 H LL
ELLN;%% -,,)"/*2 "&!2!2,! J!((*"44;#	H r<   )r9   rb   r  rc   rS  rc   r  r,   rK   r   r  rc   r  rb   r6   r   )rk   rl   rm   rn   r'   ro   r,   r  r   rp   r&   r  rU   r.   r   r7   r<   r:   r  r  	  s     -9,@,@%00$/$5$5!"49KKY)Y Y 	Y
 Y "Y Y 2Y@ '
 <@	PP P 9	P
 
P 'Pr<   r  c                  |    e Zd ZdZej
                  dej                  df	 	 	 	 	 	 	 ddZe		 d	 	 	 	 	 	 	 d	d       Z
y)
RoundBoxAnnotatorzh
    A class for drawing bounding boxes with round edges on an image
    using provided detections.
    ru   g333333?c                    t        |      | _        || _        || _        d|cxk  rdk  st	        d       t	        d      || _        y)a+  
        Args:
            color: The color or color palette to use for
                annotating detections.
            thickness: Thickness of the bounding box lines.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
            roundness: Percent of roundness for edges of bounding box.
                Value must be float 0 < roundness <= 1.0
                By default roundness percent is calculated based on smaller side
                length (width or height).
        r         ?z2roundness attribute must be float between (0, 1.0]N)r;   r9   ry   rK   r  	roundness)rS   r9   ry   rK   r   s        r:   rU   zRoundBoxAnnotator.__init__	  sQ    & ,B%+H
')59##QRR $QRR )r<   Nc                   t        |t        j                        s|S t        t	        |            D ]  }|j
                  |   j                  t              \  }}}}t        | j                  |||| j                  n|      }	t        ||z
        t        ||z
        k  rt        ||z
  dz  | j                  z        nt        ||z
  dz  | j                  z        }
||
z   ||
z   f||
z
  ||
z   f||
z
  ||
z
  f||
z   ||
z
  fg}||
z   |f||
z
  |ff|||
z   f|||
z
  ff||
z   |f||
z
  |ff|||
z   f|||
z
  ffg}d}d}t        ||||      D ]v  \  }}}}t        j                  |||
|
fd|||	j!                         | j"                         t        j$                  ||d   |d   |	j!                         | j"                         x  |S )	ae  
        Annotates the given scene with bounding boxes with rounded edges
        based on the provided detections.

        Args:
            scene: The image where rounded bounding boxes will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> round_box_annotator = sv.RoundBoxAnnotator()
            >>> annotated_frame = round_box_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![round-box-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/round-box-annotator-example-purple.png)
        r}   ru   )     r   Z   )r  ih  r  r  r   )r   r   r   r   r   r   r9   ry   rX   r   )r?   r   r   r   rZ   r   r   rc   r   r9   rK   absr   r-  r   r   r   ry   r   )rS   r   r~   r   r   r   r   r   r   r9   r	  circle_coordinatesline_coordinatesstart_angles
end_anglesr*  r   r   r   s                      r:   r   zRoundBoxAnnotator.annotate	  s-   V %,L"3z?3 6	M'__];BB3GNBB!jj%+&. "..(E rBw<#b2g,. R"WNT^^34"r'a$..89  v+f.v+f.v+f.v+f.	" v+r"R&["$56b6k"Rf$56v+r"R&["$56b6k"Rf$56	  -L,JDG"$4lJE @"D+y - &)*&,,."nn	 QQ,,."nnE6	p r<   )r9   rb   ry   rc   rK   r   r   r   r6   r   r   r7   r<   r:   r  r  	  s     -9,@,@$/$5$5*)* * "	*
 *4 '
 <@	dd d 9	d
 
d 'dr<   r  c                  J   e Zd ZdZddej
                  ej                  ej                  e
j                  df	 	 	 	 	 	 	 	 	 	 	 	 	 ddZe	 	 d	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 dd       Ze eej&                  d	d
      	 	 	 	 	 	 dd              Zy)PercentageBarAnnotatorzT
    A class for drawing percentage bars on an image using provided detections.
       P   Nc                    || _         || _        t        |      | _        t        |      | _        || _        || _        ||| _        yt        d| j                   z        | _        y)a5  
        Args:
            height: The height in pixels of the percentage bar.
            width: The width in pixels of the percentage bar.
            color: The color or color palette to use for
                annotating detections.
            border_color: The color of the border lines.
            position: The anchor position of drawing the percentage bar.
            color_lookup: Strategy for mapping colors to annotations.
                Options are `INDEX`, `CLASS`, `TRACK`.
            border_thickness: The thickness of the border lines.
        Ng333333?)	rS  r   r;   r9   border_colorr  rK   rc   border_thickness)rS   rS  r   r9   r  r  rK   r  s           r:   rU   zPercentageBarAnnotator.__init__
  sj    , "
+A%+H
#9,#G"*)5  +  	 TDKK'( 	r<   c           
     F   t        |t        j                        s|S | j                  ||       |j	                  | j
                        }t        t        |            D ]=  }||   }| j                  t        |d         t        |d         f| j                  | j                  f| j
                        }|d   d   |d   d   z
  }	|||   }
n|j                  J |j                  |   }
t        | j                  |||| j                  n|      }t!        j"                  ||d   |d   d   t        |	|
z        z   |d   d   f|j%                         d       t!        j"                  ||d   |d   | j&                  j%                         | j(                         @ |S )	aR  
        Annotates the given scene with percentage bars based on the provided
        detections. The percentage bars visually represent the confidence or custom
        values associated with each detection.

        Args:
            scene: The image where percentage bars will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.
            custom_values: Custom values array to use instead
                of the default detection confidences. This array should have the
                same length as the number of detections and contain a value between
                0 and 1 (inclusive) for each detection, representing the percentage
                to be displayed.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     confidence=np.array([0.9]),
            ...     class_id=np.array([0])
            ... )
            >>> percentage_bar_annotator = sv.PercentageBarAnnotator()
            >>> annotated_frame = percentage_bar_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![percentage-bar-example](https://media.roboflow.com/
        supervision-annotator-examples/percentage-bar-annotator-example-purple.png)
        custom_valuesr~   r  r   rX   )	anchor_xy	border_whr  r}   r   r   )r?   r   r   _validate_custom_valuesr  r  r   rZ   calculate_border_coordinatesrc   r   rS  
confidencer   r9   rK   r   r   r   r  r  )rS   r   r~   r   r  anchorsr   r  border_coordinatesborder_widthvaluer9   s               r:   r   zPercentageBarAnnotator.annotate?
  s   f %,L$$=Z$X44DMM4J"3z?3 '	M]+F!%!B!Bvay>3vay>:::t{{3 "C "
 .a036H6KA6NNL(%m4!,,888"--m<!jj%+&. "..(E MM&q)&q)!,s<%3G/HH&q)!, lln	 MM&q)&q)''..0//C'	P r<   c                   | \  }}|\  }}|t         j                  k(  r||z
  ||z
  f||ffS |t         j                  k(  r||dz  z
  |f||dz  z   ||z
  ffS |t         j                  k(  r||f||z   ||z
  ffS |t         j                  k(  r||z
  ||dz  z
  f|||dz  z   ffS |t         j
                  k(  s|t         j                  k(  r ||dz  z
  ||dz  z
  f||dz  z   ||dz  z   ffS |t         j                  k(  r|||dz  z
  f||z   ||dz  z   ffS |t         j                  k(  r||z
  |f|||z   ffS |t         j                  k(  r||dz  z
  |f||dz  z   ||z   ffS |t         j                  k(  r||f||z   ||z   ffS y Nru   r,   rr   r  	TOP_RIGHTCENTER_LEFTr  CENTER_OF_MASSCENTER_RIGHTBOTTOM_LEFTr  BOTTOM_RIGHT)r  r  r  cxcyr   rS  s          r:   r  z3PercentageBarAnnotator.calculate_border_coordinates
  s    B!vx(((JV,r2h66,,,!OR(2
?BK*HHH+++8b5j"v+666---JVq[ 01BVq[8H3III(H8O8O,Oeqj"v{"23eqj"v{"23  ...Vq[()BJVq[8H+III---J#b"v+%666///!OR(2
?BK*HHH...8b5j"v+666 /r<   c                   | |j                   t        d      y t        | t        j                  t
        f      st        d      t        |       t        |      k7  rt        d      t        d | D              st        d      y )NzThe provided detections do not contain confidence values. Please provide `custom_values` or ensure that the detections contain confidence values (e.g. by using a different model).z?custom_values must be either a numpy array or a list of floats.z@The length of custom_values must match the number of detections.c              3  <   K   | ]  }d |cxk  xr dk  nc   yw)r   rX   Nr7   ).0r  s     r:   	<genexpr>zAPercentageBarAnnotator._validate_custom_values.<locals>.<genexpr>
  s     B5qEQBs   z4All values in custom_values must be between 0 and 1.)	r  r  r?   r   r   r  r  rZ   allr  s     r:   r  z.PercentageBarAnnotator._validate_custom_values
  s    
  $$, S  - mbjj$-?@U  =!S_4 V  BMBB !WXX Cr<   z0.29.0z0.32.0)targetdeprecated_in	remove_inc                    t        | |       y r6   )r
   r  s     r:   validate_custom_valuesz-PercentageBarAnnotator.validate_custom_values
  s     	]J'r<   )rS  rc   r   rc   r9   rb   r  Color | strr  r,   rK   r   r  rf   rW  )
r   r%   r~   r   r   r   r  znpt.NDArray[np.float64] | Noneri   r%   )r  rd   r  rd   r  r,   ri   'tuple[tuple[int, int], tuple[int, int]])r  z,npt.NDArray[np.float64] | list[float] | Noner~   r   ri   rZ  )rk   rl   rm   rn   r'   ro   r&   r  r,   r  r   rp   rU   r.   r   r[  r  r  r	   __func__r1  r7   r<   r:   r  r  
  s    ,8,@,@$)KK%00$/$5$5'+!
!
 !
 *	!

 "!
 !
 "!
 %!
F '
 <@8<__ _ 9	_
 6_ 
_ '_B 7"7/>7JR7	07 78 YCYY 
Y Y4 &//
(C(( 
( (r<   r  c                      e Zd ZdZej
                  dej                  dej                  f	 	 	 	 	 	 	 	 	 ddZ
e	 d		 	 	 	 	 	 	 d
d       Ze	 	 	 	 	 	 	 	 dd       Zy)CropAnnotatorzI
    A class for drawing scaled up crops of detections on the scene.
    g       @ru   c                \    || _         || _        t        |      | _        || _        || _        y)a  
        Args:
            position: The anchor position for placing the cropped and scaled
                part of the detection in the scene.
            scale_factor: The factor by which to scale the cropped image part. A
                factor of 2, for example, would double the size of the cropped area,
                allowing for a closer view of the detection.
            border_color: The color or color palette to
                use for annotating border around the cropped area.
            border_thickness: The thickness of the border around the cropped area.
            border_color_lookup: Strategy for mapping colors to
                annotations. Options are `INDEX`, `CLASS`, `TRACK`.
        N)r  scale_factorr;   r  r  border_color_lookup)rS   r  r8  r  r  r9  s         r:   rU   zCropAnnotator.__init__
  s0    * #+#/2H2V%50C r<   Nc                
   t        |t        j                        s|S |j                  j	                  t
              D cg c]  }t        ||       }}|D cg c]  }t        || j                         }}|j                  | j                        j	                  t
              }t        t        ||            D ]  \  }	\  }
}|
j                  d   |
j                  d   f}| j                  ||| j                        \  \  }}\  }}t        ||
||f      }t!        | j"                  ||	|| j$                  n|      }t'        j(                  |||f||f|j+                         | j,                  	        |S c c}w c c}w )
a  
        Annotates the provided scene with scaled and cropped parts of the image based
        on the provided detections. Each detection is cropped from the original scene
        and scaled according to the annotator's scale factor before being placed back
        onto the scene at the specified position.


        Args:
            scene: The image where cropped detection will be placed.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.
            custom_color_lookup: Custom color lookup array.
                Allows to override the default color mapping strategy.

        Returns:
            The annotated image.

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> crop_annotator = sv.CropAnnotator()
            >>> annotated_frame = crop_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![crop-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/crop-annotator-example.png)
        )r  r   )r  r8  r  rX   r   )r  crop_whr  )r  overlayr  r}   r   )r?   r   r   r   r   rc   r0   r3   r8  r  r  rG  r-  r   calculate_crop_coordinatesr2   r   r  r9  r   r   r   r  )rS   r   r~   r   r   cropsr   resized_cropsr  rJ  resized_cropr  r;  r   r   r   r   r9   s                     r:   r   zCropAnnotator.annotate  s   Z %,L;E??;Q;QRU;V
37JU.
 
 QV
HLKd1B1BC
 
 *4)K)K== *L *

&+ 	 ,5S5P+Q 	'C',"((+\-?-?-BBG!%!@!@w "A "HRhr2 "|RQSHUE!''%!&. "55(E MMHHlln//	, A

s   E;F c                   | \  }}|\  }}|t         j                  k(  r||z
  ||z
  f||ffS |t         j                  k(  r||dz  z
  ||z
  f||dz  z   |ffS |t         j                  k(  r|||z
  f||z   |ffS |t         j                  k(  r||z
  ||dz  z
  f|||dz  z   ffS |t         j
                  k(  s|t         j                  k(  r ||dz  z
  ||dz  z
  f||dz  z   ||dz  z   ffS |t         j                  k(  r|||dz  z
  f||z   ||dz  z   ffS |t         j                  k(  r||z
  |f|||z   ffS |t         j                  k(  r||dz  z
  |f||dz  z   ||z   ffS |t         j                  k(  r||f||z   ||z   ffS y r  r  )r  r;  r  anchor_xanchor_yr   rS  s          r:   r=  z(CropAnnotator.calculate_crop_coordinatesW  s-    $(vx(((u$h&788X:NNN,,,EQJ&6(9:EQJ&1  +++h/08e3CX2NNN---E!8fk#9:8fk12  (H8O8O,OEQJ&6Q;(>?EQJ&6Q;(>?  ...8fk12E!8fk#9:  ---u$h/(Hv<M1NNN///EQJ&1EQJ&6(9:  ...h'(U*:Hv<M)NNN /r<   )
r  r,   r8  r   r  rb   r  rc   r9  r   r6   r   )r  rd   r;  rd   r  r,   ri   r3  )rk   rl   rm   rn   r,   r  r'   ro   r   rp   rU   r.   r   r[  r=  r7   r<   r:   r6  r6  
  s     &00!3?3G3G !+6+<+<DD D 1	D
 D )D6 '
 <@	NN N 9	N
 
N 'N` &O&O*9&OEM&O	0&O &Or<   r6  c                  P    e Zd ZdZej
                  ddf	 	 	 	 	 ddZedd       Zy)	BackgroundOverlayAnnotatora  
    A class for drawing a colored overlay on the background of an image outside
    the region of detections.

    If masks are provided, the background is colored outside the masks.
    If masks are not provided, the background is colored outside the bounding boxes.

    You can use the `force_box` parameter to force the annotator to use bounding boxes.

    !!! warning

        This annotator uses `sv.Detections.mask`.
    r   Fc                .    || _         || _        || _        y)a9  
        Args:
            color: The color to use for annotating detections.
            opacity: Opacity of the overlay mask. Must be between `0` and `1`.
            force_box: If `True`, forces the annotator to use bounding boxes when
                masks are provided in the supplied sv.Detections.
        N)r9   r   	force_box)rS   r9   r   rG  s       r:   rU   z#BackgroundOverlayAnnotator.__init__  s     "
"r<   c                ^   t        |t        j                        s|S t        j                  || j                  j                         t        j                        }t        j                  |d| j                  z
  || j                  d|       |j                  | j                  r>|j                  j                  t              D ]  \  }}}}|||||f   |||||f<    n4|j                  D ]%  }t        j                  |t               }	||	   ||	<   ' t        j"                  ||       |S )a  
        Applies a colored overlay to the scene outside of the detected regions.

        Args:
            scene: The image where masks will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections: Object detections to annotate.

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

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
            >>> detections = sv.Detections(
            ...     xyxy=np.array([[20, 20, 80, 80]]),
            ...     class_id=np.array([0])
            ... )
            >>> background_overlay_annotator = sv.BackgroundOverlayAnnotator()
            >>> annotated_frame = background_overlay_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections
            ... )

            ```

        ![background-overlay-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/background-color-annotator-example-purple.png)
        r   rX   r   r   )r?   r   r   	full_liker9   r   r   r   r   r   r   rG  r   r   rc   r   re   r   )
rS   r   r~   r   r   r   r   r   r   	mask_bools
             r:   r   z#BackgroundOverlayAnnotator.annotate  s   F %,L||E4::+<+<+>bhhO1t||#\4<<	
 ??"dnn",//"8"8"= ABB-22b5"R%<-@RUBrE\*A # ;JJt48	*/	*:Y'; 			%&r<   N)r9   r&   r   r   rG  re   r  )	rk   rl   rm   rn   r&   r  rU   r.   r   r7   r<   r:   rE  rE    sK      {{	## # 	#" '3 '3r<   rE  c                  0   e Zd ZdZej
                  ej                  ej                  fdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZe		 	 	 	 	 	 	 	 dd       Z
edd       Zedd	       Ze	 	 	 	 	 	 dd
       Ze	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 dd       ZddZy)ComparisonAnnotatoraH  
    Highlights the differences between two sets of detections.
    Useful for comparing results from two different models, or the difference
    between a ground truth and a prediction.

    If present, uses the oriented bounding box data.
    Otherwise, if present, uses a mask.
    Otherwise, uses the bounding box data.
    g      ?r  r  )r   label_1label_2label_overlaplabel_scalec                   || _         || _        || _        || _        || _        || _        || _        || _        t        | j                  dz         | _	        y)a{  
        Args:
            color_1: Color of areas only present in the first set of
                detections.
            color_2: Color of areas only present in the second set of
                detections.
            color_overlap: Color of areas present in both sets of detections.
            opacity: Opacity of the overlay mask. Must be between `0` and `1`.
            label_1: Label for the first set of detections.
            label_2: Label for the second set of detections.
            label_overlap: Label for areas present in both sets of detections.
            label_scale: Controls how large the labels are.
        g333333?N)
color_1color_2color_overlapr   rM  rN  rO  rP  rc   r  )	rS   rR  rS  rT  r   rM  rN  rO  rP  s	            r:   rU   zComparisonAnnotator.__init__  sW    4 **&!$"2"2S"89r<   c                   t        |t        j                        s|S |j                         r|j                         r|S | j	                  ||      }| j                  ||      }|r%| j                  ||      }| j                  ||      }nK|r%| j                  ||      }| j                  ||      }n$| j                  ||      }| j                  ||      }||z  }|| z  }|| z  }t        j                  |t        j                        }	| j                  j                         |	|<   | j                  j                         |	|<   | j                  j                         |	|<   d| j                  z
  ||   z  | j                  |	|   z  z   ||<   d| j                  z
  ||   z  | j                  |	|   z  z   ||<   d| j                  z
  ||   z  | j                  |	|   z  z   ||<   | j!                  |       |S )aL  
        Highlights the differences between two sets of detections.

        Args:
            scene: The image where detections will be drawn.
                `ImageType` is a flexible type, accepting either `numpy.ndarray`
                or `PIL.Image.Image`.
            detections_1: The first set of detections or predictions.
            detections_2: The second set of detections to compare or
                ground truth.

        Returns:
            The annotated image.

        Example:
            ```python
            import supervision as sv

            image = ...
            detections_1 = sv.Detections(...)
            detections_2 = sv.Detections(...)

            comparison_annotator = sv.ComparisonAnnotator()
            annotated_frame = comparison_annotator.annotate(
                scene=image.copy(),
                detections_1=detections_1,
                detections_2=detections_2
            )
            ```

        ![comparison-annotator-example](https://media.roboflow.com/
        supervision-annotator-examples/comparison-annotator-example.png)
        r   rX   )r?   r   r   is_empty_use_obb	_use_mask_mask_from_obb_mask_from_mask_mask_from_xyxyr   r   rT  r   rR  rS  r   r#  )
rS   r   detections_1detections_2use_obbuse_maskmask_1mask_2mask_overlapcolor_layers
             r:   r   zComparisonAnnotator.annotate  s   J %,L  "|'<'<'>L--l;>>,=((=F((=F))%>F))%>F ))%>F))%>F<-'<-'mmE:$($6$6$=$=$?L!"ll113F"ll113F 4<</54
 
LL;|445l T\\)U6]:T\\KM
 >
 
f T\\)U6]:T\\KM
 >
 
f 	% r<   c                    | j                         r|j                         rJ t        | j                  v }t        |j                  v }|xr |xs* |xr |j                         xs | j                         xr |S r6   )rV  r   r   )r\  r]  is_obb_1is_obb_2s       r:   rW  zComparisonAnnotator._use_obbX  sx    ((*,2G2G2III+|/@/@@+|/@/@@"( 64\2246%%'4H	
r<   c                    | j                         r|j                         rJ | j                  d u}|j                  d u}|xr |xs* |xr |j                         xs | j                         xr |S r6   )rV  r   )r\  r]  	is_mask_1	is_mask_2s       r:   rX  zComparisonAnnotator._use_maskc  sx    ((*,2G2G2III %%T1	 %%T1	$9 75l3357%%'5I	
r<   c                `   t        j                  | j                  d d t         j                        }|j	                         r|S | j                  d   | j                  d   f}t        |j                        }|D ]1  }t        ||      }||j                  t         j                        z  }3 |S Nru   r   rX   r   )r[   )	r   r   r   bool_rV  r$   r   r#   r   )r   r~   r   r[   polygonsr   polygon_masks          r:   r[  z#ComparisonAnnotator._mask_from_xyxyn  s     xxBQrxx8 KAA6#JOO4 	2G*7-PLL''11D	2 r<   c                X   t        j                  | j                  d d t         j                        }|j	                         r|S | j                  d   | j                  d   f}|j
                  t           D ]1  }t        ||      }||j                  t         j                        z  }3 |S rk  )	r   r   r   rl  rV  r   r   r#   r   )r   r~   r   r[   r   rn  s         r:   rY  z"ComparisonAnnotator._mask_from_obb~  s     xxBQrxx8 KAA6!'?@ 	2G*7-PLL''11D	2 r<   c                   t        j                  | j                  d d t         j                        }|j	                         r|S |j
                  J |j
                  D ]$  }||j                  t         j                        z  }& |S )Nru   r   )r   r   r   rl  rV  r   r   )r   r~   r   detections_masks       r:   rZ  z#ComparisonAnnotator._mask_from_mask  st     xxBQrxx8 K***) 	5OO**28844D	5r<   c           
        t        d| j                  z        }t        d| j                  z        }t        d| j                  z        }t        d| j                  z        }t        d| j                  z        }t        d| j                  z        }t        d| j                  z        }t        d| j                  z        }	| j                  }
| j                  | j                  f| j                  | j
                  f| j                  | j                  fg}|}|D ]  \  }}|s	t        j                  |t        | j                  | j                        d   \  }}||z   |dz  z   }||dz  z   }||dz  z   }t        |t        ||||	      t        j                  |
       t        |t        ||z   ||dz  z
  ||	      ||	
       t!        ||t#        ||z   |      |
| j                         |||z   z  } y)z
        Draw the labels, explaining what each color represents, with automatically
        computed positions.

        Args:
            scene: The image where the labels will be drawn.
        2   r   r  rH   rW   r%  r   ru   )r   r  r   rS  )r   rectr9   rP   )r   r  )rN   r  r  N)rc   rP  rM  rR  rN  rS  rO  rT  r   r.  r/  r  r)   r-   r&   rq   r*   r+   )rS   r   margingapy0rS  marker_sizepaddingtext_box_corner_radiusmarker_corner_radiusr  label_color_pairsx0r&  r9   r9  rE   r   center_xcenter_ys                       r:   r#  z ComparisonAnnotator._draw_labels  s    R$***+"t'''(d&&&'R$***+"t///0b4+++,!$R$*:*:%:!;"1t'7'7#78%%
 \\4<<(\\4<<(!3!34
 , *	KD%//!**--	
 KVQ [(7Q;6EEQJHFaK'H"B"E&Akk4	 #7lq0%&	 2
 !H{$:hG%#22 %#+BU*	r<   N)rR  r&   rS  r&   rT  r&   r   r   rM  r@   rN  r@   rO  r@   rP  r   )r   r%   r\  r   r]  r   ri   r%   )r\  r   r]  r   ri   re   )r   rj   r~   r   ri   znpt.NDArray[np.bool_])r   rj   ri   rZ  )rk   rl   rm   rn   r&   REDGREENBLUErU   r.   r   r[  rW  rX  r[  rY  rZ  r#  r7   r<   r:   rL  rL    su    $zz	#:  #:#: #: 	#: #: #: #: #: #:J 'MM.8MHRM	M 'M^ 
 
 
 
 $2<	  $2<	  
$
2<
	
 
Dr<   rL  )r9   r2  ri   r&   )r9   rb   ri   Color | ColorPalette)F)r   rj   r~   r   r9   r  rK   z"ColorLookup | npt.NDArray[np.int_]r   re   ri   znpt.NDArray[np.bool_] | None)j
__future__r   	functoolsr   mathr   typingr   r   r   r   numpyr   numpy.typingr  	deprecater	   r
   PILr   r   r   scipy.interpolater   r   supervision.annotators.baser   supervision.annotators.utilsr   r   r   r   r   r   r   r   r   r   r   r   supervision.configr   "supervision.detection.compact_maskr   supervision.detection.corer   !supervision.detection.utils.boxesr    r!   &supervision.detection.utils.convertersr"   r#   r$   supervision.draw.baser%   supervision.draw.colorr&   r'   supervision.draw.utilsr(   r)   r*   supervision.geometry.corer+   r,   r-   supervision.utils.conversionr.   r/   supervision.utils.imager0   r1   r2   r3   supervision.utils.loggerr4   rk   r  r;   FONT_HERSHEY_SIMPLEXr/  rG   rt   r   r   r   r   r   r   r   r   r  r  r  r_  r  r  r  r  r  r  r  r  r6  rE  rL  r7   r<   r:   <module>r     s|   "   & & 
   & + + , 5    8 : 1 J 
 , 6 R R ; ;  1	X	 
 < 
 < 
% 


 ##h#- h#VT= TnT= Tz  7!77  7 5	7
 7 "7tUM Up\} \~Y] YxcM cL`} `F\ \~Ym Yxl= l^x( xv	Q0, Q0hjM jZJM JZN] Nbm} m`[ [|w wtE EPL(] L(^XOM XOvT TnF Fr<   