§
    >²¸j;C  ã                   ól  — d dl Z d dlmZ d dlZd dlmZ d dlmZ	 d dl
mZ d dlmZmZ ej        dfdej        ej                 ded	ed
ededej        ej                 fd„Zej        dfdej        ej                 ded
ededej        ej                 f
d„Zej        dfdej        ej                 ded
ededej        ej                 f
d„Zdej        ej                 ded
ededej        ej                 f
d„Zej        dfdej        ej                 dej        ej                 d
ededej        ej                 f
d„Zej        dfdej        ej                 dej        ej                 d
ededej        ej                 f
d„Zej        ddde	j        dfdej        ej                 dedededededed ed!edz  dej        ej                 fd"„Zdej        ej                 d#eej        ej                 z  dededej        ej                 f
d$„Zd%e eef         defd&„Z!d%e eef         defd'„Z"dS )(é    N)Úcast)Ú_cv2)ÚColor)ÚPointÚRecté   ÚsceneÚstartÚendÚcolorÚ	thicknessÚreturnc                 ó¤   — t          j        | |                     ¦   «         |                     ¦   «         |                     ¦   «         |¬¦  «         | S )aH  
    Draws a line on a given scene.

    Args:
        scene: The scene on which the line will be drawn
        start: The starting point of the line
        end: The end point of the line
        color: The color of the line, defaults to Color.ROBOFLOW
        thickness: The thickness of the line

    Returns:
        The scene with the line drawn on it

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_line
        >>> from supervision.draw.color import Color
        >>> from supervision.geometry.core import Point
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> scene = draw_line(
        ...     scene, start=Point(x=10, y=10), end=Point(x=90, y=90), color=Color.RED
        ... )
        >>> scene.shape
        (100, 100, 3)

        ```
    ©r   )Úcv2ÚlineÚas_xy_int_tupleÚas_bgr)r	   r
   r   r   r   s        úf/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/draw/utils.pyÚ	draw_liner      sT   € õF „HØØ×ÒÑÔØ×ÒÑÔØ�Š‰ŒØðñ ô ð ð €Ló    Úrectc                 ó¸   — t          j        | |j                             ¦   «         |j                             ¦   «         |                     ¦   «         |¬¦  «         | S )a  
    Draws a rectangle on an image.

    Args:
        scene: The scene on which the rectangle will be drawn
        rect: The rectangle to be drawn
        color: The color of the rectangle
        thickness: The thickness of the rectangle border

    Returns:
        The scene with the rectangle drawn on it

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_rectangle
        >>> from supervision.draw.color import Color
        >>> from supervision.geometry.core import Rect
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> rect = Rect(x=10, y=10, width=50, height=30)
        >>> scene = draw_rectangle(scene, rect, color=Color.RED)
        >>> scene.shape
        (100, 100, 3)

        ```
    r   )r   Ú	rectangleÚtop_leftr   Úbottom_rightr   )r	   r   r   r   s       r   Údraw_rectangler   9   sY   € õ@ „MØØŒ×%Ò%Ñ'Ô'ØÔ×)Ò)Ñ+Ô+Ø�Š‰ŒØðñ ô ð ð €Lr   é   Úopacityc                 óÖ  — |dk    rYt          j        | |j                             ¦   «         |j                             ¦   «         |                     ¦   «         d¦  «         n‰|                      ¦   «         }t          j        ||j                             ¦   «         |j                             ¦   «         |                     ¦   «         d¦  «         t          j        ||| d|z
  d| ¬¦  «         | S )a@  
    Draws a filled rectangle on an image.

    Args:
        scene: The scene on which the rectangle will be drawn
        rect: The rectangle to be drawn
        color: The color of the rectangle
        opacity: The opacity of rectangle when drawn on the scene.

    Returns:
        The scene with the rectangle drawn on it

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_filled_rectangle
        >>> from supervision.draw.color import Color
        >>> from supervision.geometry.core import Rect
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> rect = Rect(x=10, y=10, width=50, height=30)
        >>> scene = draw_filled_rectangle(scene, rect, color=Color.RED, opacity=0.5)
        >>> scene.shape
        (100, 100, 3)

        ```
    r   éÿÿÿÿr   ©ÚgammaÚdst)r   r   r   r   r   r   ÚcopyÚaddWeighted)r	   r   r   r   Úscene_with_annotationss        r   Údraw_filled_rectangler(   c   sæ   € ð@ �!‚|€|ÝŒØØŒM×)Ò)Ñ+Ô+ØÔ×-Ò-Ñ/Ô/Ø�LŠL‰NŒNØñ	
ô 	
ð 	
ð 	
ð "'§¢¡¤ÐÝŒØ"ØŒM×)Ò)Ñ+Ô+ØÔ×-Ò-Ñ/Ô/Ø�LŠL‰NŒNØñ	
ô 	
ð 	
õ 	ŒØ" G¨U°A¸±KÀqÈeð	
ñ 	
ô 	
ð 	
ð €Lr   Úborder_radiusc                 óX  — |                      ¦   «         \  }}}}||z
  ||z
  }	}t          |t          ||	¦  «        dz  ¦  «        }|dk    r1t          j        | ||f||f|                     ¦   «         d¬¦  «         | S ||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 ]9}t          j        | |d         |d         |                     ¦   «         d¬¦  «         Œ:|D ]-}t          j        | |||                     ¦   «         d¬¦  «         Œ.| S )a‘  
    Draws a rounded rectangle on an image.

    Args:
        scene: The image on which the rounded rectangle will be drawn.
        rect: The rectangle to be drawn.
        color: The color of the rounded rectangle.
        border_radius: The radius of the corner rounding in pixels. Values <= 0
            (or values clamped to 0 when the rectangle is too small) draw a
            plain filled rectangle with square corners. Note: previously,
            a negative value that remained negative after clamping would raise
            ``cv2.error``; it now draws square corners silently.

    Returns:
        The image with the rounded rectangle drawn on it.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_rounded_rectangle
        >>> from supervision.draw.color import Color
        >>> from supervision.geometry.core import Rect
        >>> scene = np.zeros((200, 300, 3), dtype=np.uint8)
        >>> rect = Rect(x=20, y=30, width=120, height=80)
        >>> scene = draw_rounded_rectangle(scene, rect, Color.RED, border_radius=0)
        >>> scene.shape
        (200, 300, 3)

        ```
    r   r   r!   )ÚimgÚpt1Úpt2r   r   r   )r+   ÚcenterÚradiusr   r   )Úas_xyxy_int_tupleÚminr   r   r   Úcircle)r	   r   r   r)   Úx1Úy1Úx2Úy2ÚwidthÚheightÚrectangle_coordinatesÚcircle_centersÚcoordinatesr.   s                 r   Údraw_rounded_rectangler<   ›   sÇ  € ðH ×+Ò+Ñ-Ô-�N€BˆˆB�Ø˜‘G˜R "™Wˆ6€EÝ˜¥s¨5°&Ñ'9Ô'9¸QÑ'>Ñ?Ô?€Mà˜ÒÐõ 	ŒØØ�R�Ø�R�Ø—,’,‘.”.Øð	
ñ 	
ô 	
ð 	
ð ˆð ˆ}Ñ
˜bÐ	! B¨Ñ$6¸Ð#;Ð<Ø
ˆb�=Ñ Ð	! B¨¨]Ñ(:Ð#;Ð<ðÐð
 
ˆmÑ	˜R -Ñ/Ð0Ø	ˆmÑ	˜R -Ñ/Ð0Ø	ˆmÑ	˜R -Ñ/Ð0Ø	ˆmÑ	˜R -Ñ/Ð0ð	€Nð -ð 
ð 
ˆÝŒØØ˜A”Ø˜A”Ø—,’,‘.”.Øð	
ñ 	
ô 	
ð 	
ð 	
ð !ð 
ð 
ˆÝŒ
ØØØ Ø—,’,‘.”.Øð	
ñ 	
ô 	
ð 	
ð 	
ð €Lr   Úpolygonc                 ó^   — t          j        | |gd|                     ¦   «         |¬¦  «         | S )a  Draw a polygon on a scene.

    Args:
        scene: The scene to draw the polygon on.
        polygon: The polygon to be drawn, given as a list of vertices.
        color: The color of the polygon. Defaults to Color.ROBOFLOW.
        thickness: The thickness of the polygon lines, by default 2.

    Returns:
        The scene with the polygon drawn on it.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_polygon
        >>> from supervision.draw.color import Color
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> polygon = np.array([[10, 10], [90, 10], [90, 90], [10, 90]])
        >>> scene = draw_polygon(scene, polygon, color=Color.RED)
        >>> scene.shape
        (100, 100, 3)

        ```
    T)ÚisClosedr   r   )r   Ú	polylinesr   )r	   r=   r   r   s       r   Údraw_polygonrA   í   s9   € õ< „MØ�ˆy 4¨u¯|ª|©~¬~Èðñ ô ð ð €Lr   c                 ó  — |dk    r+t          j        | |g|                     ¦   «         ¬¦  «         n[|                      ¦   «         }t          j        ||g|                     ¦   «         ¬¦  «         t          j        ||| d|z
  d| ¬¦  «         | S )a9  Draw a filled polygon on a scene.

    Args:
        scene: The scene to draw the polygon on.
        polygon: The polygon to be drawn, given as a list of vertices.
        color: The color of the polygon. Defaults to Color.ROBOFLOW.
        opacity: The opacity of polygon when drawn on the scene.

    Returns:
        The scene with the polygon drawn on it.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_filled_polygon
        >>> from supervision.draw.color import Color
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> polygon = np.array([[10, 10], [90, 10], [90, 90], [10, 90]])
        >>> scene = draw_filled_polygon(scene, polygon, color=Color.RED, opacity=0.5)
        >>> scene.shape
        (100, 100, 3)

        ```
    r   )r   r   r"   )r   ÚfillPolyr   r%   r&   )r	   r=   r   r   r'   s        r   Údraw_filled_polygonrD     s’   € ð< �!‚|€|ÝŒ�U˜W˜I¨U¯\ª\©^¬^Ð<Ñ<Ô<Ð<Ð<à!&§¢¡¤ÐÝŒÐ+¨g¨Y¸e¿lºl¹n¼nÐMÑMÔMÐMÝŒØ" G¨U°A¸±KÀqÈeð	
ñ 	
ô 	
ð 	
ð €Lr   g      à?é
   ÚtextÚtext_anchorÚ
text_colorÚ
text_scaleÚtext_thicknessÚtext_paddingÚ	text_fontÚbackground_colorc	           
      óŽ  — t          j        ||||¬¦  «        d         \  }	}
|                     ¦   «         \  }}t          ||	dz  z
  ||
dz  z
  |	|
¬¦  «                             |¦  «        }|�t          | ||¬¦  «        } t          j        | |||	dz  z
  ||
dz  z   f|||                     ¦   «         |t           j        ¬¦  «         | S )a®  
    Draw text with background on a scene.

    Args:
        scene: A numpy ndarray representing the image, typically of shape
            (H, W, 3) for a color BGR image or (H, W) for grayscale,
            with dtype uint8.
        text: The text to be drawn.
        text_anchor: The anchor point for the text, represented as a
            Point object with x and y attributes.
        text_color: The color of the text. Defaults to black.
        text_scale: The scale of the text. Defaults to 0.5.
        text_thickness: The thickness of the text. Defaults to 1.
        text_padding: The amount of padding to add around the text
            when drawing a rectangle in the background. Defaults to 10.
        text_font: The font to use for the text.
            Defaults to cv2.FONT_HERSHEY_SIMPLEX.
        background_color: The color of the background rectangle,
            if one is to be drawn. Defaults to None.

    Returns:
        The input scene with the text drawn on it.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> from supervision.geometry.core import Point
        >>> from supervision.draw.utils import draw_text
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> text_anchor = Point(x=50, y=50)
        >>> scene = draw_text(
        ...     scene=scene, text="Hello, world!", text_anchor=text_anchor
        ... )
        >>> scene.shape
        (100, 100, 3)

        ```
    )rF   ÚfontFaceÚ	fontScaler   r   r   )ÚxÚyr7   r8   N)r	   r   r   )r+   rF   ÚorgrO   rP   r   r   ÚlineType)	r   ÚgetTextSizer   r   Úpadr(   ÚputTextr   ÚLINE_AA)r	   rF   rG   rH   rI   rJ   rK   rL   rM   Ú
text_widthÚtext_heightÚtext_anchor_xÚtext_anchor_yÚ	text_rects                 r   Ú	draw_textr^   ;  s  € õb "œoØØØØ ð	ñ ô ð
 ô	Ñ€J�ð $/×#>Ò#>Ñ#@Ô#@Ñ €M�=åØ
˜*¨™/Ñ
)Ø
˜+¨Ñ*Ñ
*ØØð	ñ ô ÷
 
‚cˆ,ÑÔð ð Ð#Ý%Ø˜iÐ/?ð
ñ 
ô 
ˆõ „KØØØ˜Z¨1™_Ñ,¨m¸kÈQÑ>NÑ.NÐOØØØ×ÒÑ!Ô!Ø Ý”ð	ñ 	ô 	ð 	ð €Lr   Úimagec           	      ó$  — t          |t          ¦  «        rît          j                             |¦  «        st          d|› d�¦  «        ‚t          j        |t          j        ¦  «        }|€t          d|› d�¦  «        ‚|j
        t          j        k    rHt          j        t          j        |dz  ¦  «        dd¦  «                             t          j        ¦  «        }t#          t$          j        t          j                 |¦  «        }n|}|j        d	k    s|j        d
         dvrt-          d¦  «        ‚d|cxk    rdk    sn t-          d¦  «        ‚t/          |j        ¦  «        }t/          |j        ¦  «        }t/          |j        ¦  «        }t/          |j        ¦  «        }	|dk     s.|dk     s(||z   | j        d         k    s||	z   | j        d         k    rt-          d¦  «        ‚t#          t$          j        t          j                 t          j        |||	f¦  «        ¦  «        }|j        d
         dk    r|dd…dd…d	f         nt          j        |	|f|j
        ¬¦  «        dz  }
t          j        |
|z  ¦  «        }| |||	z   …|||z   …f         }|                     t          j        ¦  «        dz  }t          j        d|dt          j         f         z
  |z  |dt          j         f         |dd…dd…dd	…f         z  z   ¦  «        }|| |||	z   …|||z   …f<   | S )a°  
    Draws an image onto a given scene with specified opacity and dimensions.

    Args:
        scene: Background image where the new image will be drawn.
        image: Image to draw, either a file path or an already-loaded image array.
            A 2-D grayscale image is not accepted, whether it is passed as an array
            or read from a path; convert it to BGR first, for example with
            `cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)`. A 16-bit image read from a
            path is scaled down to the 8 bits of the scene.
        opacity: Opacity of the image to be drawn.
        rect: Rectangle specifying where to draw the image.

    Returns:
        The updated scene.

    Raises:
        FileNotFoundError: If the image path does not exist.
        OSError: If the image path exists but cannot be decoded.
        ValueError: If the image is not 3-D with 3 (BGR) or 4 (BGRA) channels, or
            for invalid opacity or rectangle dimensions.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.draw.utils import draw_image
        >>> from supervision.geometry.core import Rect
        >>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> image = np.full((40, 40, 3), 255, dtype=np.uint8)
        >>> rect = Rect(x=10, y=10, width=40, height=40)
        >>> scene = draw_image(scene, image, opacity=0.8, rect=rect)
        >>> scene.shape
        (100, 100, 3)

        ```
    zImage path ('z') does not exist.NzCould not decode image path ('z').é   r   éÿ   é   r   )rc   é   z Image must have 3 or 4 channels.g        g      ð?z$Opacity must be between 0.0 and 1.0.r   zInvalid rectangle dimensions.rd   )Údtypeg     ào@.)!Ú
isinstanceÚstrÚosÚpathÚexistsÚFileNotFoundErrorr   ÚimreadÚIMREAD_UNCHANGEDÚOSErrorre   ÚnpÚuint16ÚclipÚrintÚastypeÚuint8r   ÚnptÚNDArrayÚndimÚshapeÚ
ValueErrorÚintrQ   rR   r7   r8   ÚresizeÚonesÚconvertScaleAbsÚfloat32Únewaxis)r	   r_   r   r   Úloaded_imageÚimage_npÚrect_xÚrect_yÚ
rect_widthÚrect_heightÚalpha_channelÚalpha_scaledÚ	scene_roiÚalpha_floatÚblended_rois                  r   Ú
draw_imager‹   Ž  s  € õX �%�ÑÔð ÝŒw�~Š~˜eÑ$Ô$ð 	OÝ#Ð$M°EÐ$MÐ$MÐ$MÑNÔNÐNÝ”z %­Ô)=Ñ>Ô>ˆØÐÝÐE¸5ÐEÐEÐEÑFÔFÐFØÔ¥¤Ò*Ð*õ œ7¥2¤7¨<¸#Ñ+=Ñ#>Ô#>ÀÀ3ÑGÔG×NÒNÍrÌxÑXÔXˆLÝ�œ¥B¤HÔ-¨|Ñ<Ô<ˆˆàˆà„}˜ÒÐ˜Xœ^¨AÔ.°fÐ<Ð<ÝÐ;Ñ<Ô<Ð<ð �'Ð Ð Ò Ð ˜SÒ Ð Ð Ð ÝÐ?Ñ@Ô@Ð@å�”‰[Œ[€FÝ�”‰[Œ[€FÝ�T”Z‘”€JÝ�d”kÑ"Ô"€Kð 	�Š
ˆ
Ø�AŠ:ˆ:Ø�JÑ ¤¨Q¤Ò/Ð/Ø�KÑ %¤+¨a¤.Ò0Ð0åÐ8Ñ9Ô9Ð9õ ÝŒ•B”HÔ�sœz¨(°ZÀÐ4MÑNÔNñô €Hð
 Œ>˜!Ô Ò!Ð!ð 	����A�A�A�q�ÔÐåŒW�k :Ð.°h´nÐEÑEÔEÈÑKð õ
 Ô& }°wÑ'>Ñ?Ô?€Lð �f˜v¨Ñ3Ð3°V¸fÀzÑ>QÐ5QÐQÔR€IØ×%Ò%¥b¤jÑ1Ô1°EÑ9€KÝÔ%Ø	
ˆ[˜�bœj˜Ô)Ñ	)¨YÑ6Ø
�c�2œ:�oÔ
&¨°!°!°!°Q°Q°Q¸¸¸°(Ô);Ñ
;ñ	<ñô €Kð JU€Eˆ&�6˜KÑ'Ð
'¨°&¸:Ñ2EÐ)EÐ
EÑFà€Lr   Úresolution_whc                 ó&   — t          | ¦  «        dz  S )a)  
    Calculate optimal font scale based on image resolution. Adjusts font scale
    proportionally to the smallest dimension of the given image resolution for
    consistent readability.

    Args:
        resolution_wh: A tuple of `(width, height)` of the image in pixels.

    Returns:
        Recommended font scale factor.

    Examples:
        ```pycon
        >>> import supervision as sv
        >>> sv.calculate_optimal_text_scale((1920, 1080))
        1.08
        >>> sv.calculate_optimal_text_scale((640, 480))
        0.48

        ```
    gü©ñÒMbP?©r1   ©rŒ   s    r   Úcalculate_optimal_text_scaler�   õ  s   € õ, ˆ}ÑÔ Ñ$Ð$r   c                 ó0   — t          | ¦  «        dk     rdS dS )a1  
    Calculate optimal line thickness based on image resolution. Adjusts the line
    thickness for readability depending on the smallest dimension of the provided
    image resolution.

    Args:
        resolution_wh: A tuple of `(width, height)` of the image in pixels.

    Returns:
        Recommended line thickness in pixels.

    Examples:
        ```pycon
        >>> import supervision as sv
        >>> sv.calculate_optimal_line_thickness((1920, 1080))
        4
        >>> sv.calculate_optimal_line_thickness((640, 480))
        2

        ```
    i8  r   rd   rŽ   r�   s    r   Ú calculate_optimal_line_thicknessr’     s!   € õ, ˆ=ÑÔ˜DÒ Ð ØˆqØˆ1r   )#rh   Útypingr   Únumpyro   Únumpy.typingru   Úsupervisionr   r   Úsupervision.draw.colorr   Úsupervision.geometry.corer   r   ÚROBOFLOWrv   rt   rz   r   r   Úfloatr(   r<   Úint_rA   rD   ÚBLACKÚFONT_HERSHEY_SIMPLEXrg   r^   r‹   Útupler�   r’   © r   r   ú<module>r       sj  ðØ 	€	€	€	Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð à #Ð #Ð #Ð #Ð #Ð #Ø (Ð (Ð (Ð (Ð (Ð (Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1ð ”>Øð*ð *ØŒ;�r”xÔ ð*àð*ð 
ð*ð ð	*ð
 ð*ð 	„[�”Ôð*ð *ð *ð *ð` ”>Øð	'ð 'ØŒ;�r”xÔ ð'à
ð'ð ð'ð ð	'ð
 	„[�”Ôð'ð 'ð 'ð 'ðZ ”>Øð	5ð 5ØŒ;�r”xÔ ð5à
ð5ð ð5ð ð	5ð
 	„[�”Ôð5ð 5ð 5ð 5ðpOØŒ;�r”xÔ ðOà
ðOð ðOð ð	Oð
 	„[�”ÔðOð Oð Oð Oðj ”>Øð	!ð !ØŒ;�r”xÔ ð!àŒ[˜œÔ!ð!ð ð!ð ð	!ð
 	„[�”Ôð!ð !ð !ð !ðN ”>Øð	'ð 'ØŒ;�r”xÔ ð'àŒ[˜œÔ!ð'ð ð'ð ð	'ð
 	„[�”Ôð'ð 'ð 'ð 'ð\ œØØØØÔ-Ø%)ðPð PØŒ;�r”xÔ ðPà
ðPð ðPð ð	Pð
 ðPð ðPð ðPð ðPð ˜d‘lðPð 	„[�”ÔðPð Pð Pð PðfdØŒ;�r”xÔ ðdà�”˜RœXÔ&Ñ&ðdð ðdð ð	dð
 	„[�”Ôðdð dð dð dðN%°°c¸3°h´ð %ÀEð %ð %ð %ð %ð2°E¸#¸s¸(´Oð Èð ð ð ð ð ð r   