Ë
    ¼Ó^jj/  ã                  ó  — d dl mZ d dlZd dlmZ d dlZd dlZd dlmZ	 d dl
mZ d dlmZmZ ej                  df	 	 	 	 	 	 	 	 	 	 	 dd„Zej                  df	 	 	 	 	 	 	 	 	 dd„Zej                  d	f	 	 	 	 	 	 	 	 	 dd
„Z	 	 	 	 	 	 	 	 	 	 dd„Zej                  df	 	 	 	 	 	 	 	 	 dd„Zej                  d	f	 	 	 	 	 	 	 	 	 dd„Zej,                  dd	dej.                  df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Zy)é    )ÚannotationsN)Úcast)ÚColor)ÚPointÚRecté   c                óŽ   — t        j                  | |j                  «       |j                  «       |j                  «       |¬«       | S )ai  
    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
    ©Ú	thickness)Úcv2ÚlineÚas_xy_int_tupleÚas_bgr)ÚsceneÚstartÚendÚcolorr   s        úa/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/draw/utils.pyÚ	draw_liner      s>   € ô( ‡H�HØØ×ÑÓØ×ÑÓØ�‰‹Øõð €Ló    c                ó¶   — t        j                  | |j                  j                  «       |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
    r
   )r   Ú	rectangleÚtop_leftr   Úbottom_rightr   )r   Úrectr   r   s       r   Údraw_rectangler   ,   sH   € ô$ ‡M�MØØ�‰×%Ñ%Ó'Ø×Ñ×)Ñ)Ó+Ø�‰‹Øõð €Lr   é   c                óÌ  — |dk(  rYt        j                  | |j                  j                  «       |j                  j                  «       |j                  «       d«       | S | j                  «       }t        j                  ||j                  j                  «       |j                  j                  «       |j                  «       d«       t        j                  ||| d|z
  d| ¬«       | S )aL  
    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
    r   éÿÿÿÿr   ©ÚgammaÚdst)r   r   r   r   r   r   ÚcopyÚaddWeighted)r   r   r   ÚopacityÚscene_with_annotationss        r   Údraw_filled_rectangler'   H   sÀ   € ð$ �!‚|Ü�‰ØØ�M‰M×)Ñ)Ó+Ø×Ñ×-Ñ-Ó/Ø�L‰L‹NØô	
ð( €Lð "'§¡£ÐÜ�‰Ø"Ø�M‰M×)Ñ)Ó+Ø×Ñ×-Ñ-Ó/Ø�L‰L‹NØô	
ô 	�‰Ø" G¨U°A¸±KÀqÈeõ	
ð €Lr   c                óÂ  — |j                  «       \  }}}}||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 ]0  }t        j                  | |d   |d   |j	                  «       d¬«       Œ2 |D ]*  }t        j
                  | |||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.

    Returns:
        The image with the rounded rectangle drawn on it.
    r   r   r   r   )ÚimgÚpt1Úpt2r   r   )r)   ÚcenterÚradiusr   r   )Úas_xyxy_int_tupleÚminr   r   r   Úcircle)r   r   r   Úborder_radiusÚx1Úy1Úx2Úy2ÚwidthÚheightÚrectangle_coordinatesÚcircle_centersÚcoordinatesr,   s                 r   Údraw_rounded_rectangler;   r   sI  € ð$ ×+Ñ+Ó-�N€BˆˆB�Ø˜‘G˜R "™Wˆ6€EÜ˜¤s¨5°&Ó'9¸QÑ'>Ó?€Mð ˆ}Ñ
˜bÐ	! B¨Ñ$6¸Ð#;Ð<Ø
ˆb�=Ñ Ð	! B¨¨]Ñ(:Ð#;Ð<ðÐð
 
ˆmÑ	˜R -Ñ/Ð0Ø	ˆmÑ	˜R -Ñ/Ð0Ø	ˆmÑ	˜R -Ñ/Ð0Ø	ˆmÑ	˜R -Ñ/Ð0ð	€Nð -ò 
ˆÜ�‰ØØ˜A‘Ø˜A‘Ø—,‘,“.Øö	
ð
ð !ò 
ˆÜ�
‰
ØØØ Ø—,‘,“.Øö	
ð
ð €Lr   c                óX   — t        j                  | |gd|j                  «       |¬«       | S )aj  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.
    T)ÚisClosedr   r   )r   Ú	polylinesr   )r   Úpolygonr   r   s       r   Údraw_polygonr@   ¦   s*   € ô" ‡M�MØ�ˆy 4¨u¯|©|«~Èõð €Lr   c                ó  — |dk(  r)t        j                  | |g|j                  «       ¬«       | S | j                  «       }t        j                  ||g|j                  «       ¬«       t        j                  ||| d|z
  d| ¬«       | S )am  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.
    r   )r   r   r    )r   ÚfillPolyr   r#   r$   )r   r?   r   r%   r&   s        r   Údraw_filled_polygonrC   ½   su   € ð" �!‚|Ü�‰�U˜W˜I¨U¯\©\«^Õ<ð €Lð "'§¡£ÐÜ�‰Ð+¨g¨Y¸e¿l¹l»nÕMÜ�‰Ø" G¨U°A¸±KÀqÈeõ	
ð €Lr   g      à?é
   c	           
     ól  — t        j                  ||||¬«      d   \  }	}
|j                  «       \  }}t        ||	dz  z
  ||
dz  z
  |	|
¬«      j	                  |«      }|�t        | ||¬«      } t        j                  | |||	dz  z
  ||
dz  z   f|||j                  «       |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)

        ```
    )ÚtextÚfontFaceÚ	fontScaler   r   r   )ÚxÚyr6   r7   )r   r   r   )r)   rF   ÚorgrG   rH   r   r   ÚlineType)	r   ÚgetTextSizer   r   Úpadr'   ÚputTextr   ÚLINE_AA)r   rF   Útext_anchorÚ
text_colorÚ
text_scaleÚtext_thicknessÚtext_paddingÚ	text_fontÚbackground_colorÚ
text_widthÚtext_heightÚtext_anchor_xÚtext_anchor_yÚ	text_rects                 r   Ú	draw_textr]   Ú   sç   € ôb "Ÿo™oØØØØ ô	ð
 ñ	Ñ€J�ð $/×#>Ñ#>Ó#@Ñ €M�=äØ
˜*¨™/Ñ
)Ø
˜+¨Ñ*Ñ
*ØØô	÷
 
�cˆ,Óð ð Ð#Ü%Ø˜iÐ/?ô
ˆô ‡K�KØØØ˜Z¨1™_Ñ,¨m¸kÈQÑ>NÑ.NÐOØØØ×ÑÓ!Ø Ü—‘õ	ð €Lr   c           	     ó   — t        |t        «      rRt        j                  j	                  |«      st        d|› d�«      ‚t        j                  |t        j                  «      }d|cxk  rdk  st        d«      ‚ t        d«      ‚t        |j                  «      }t        |j                  «      }t        |j                  «      }t        |j                  «      }|dk  s/|dk  s*||z   | j                  d   kD  s||z   | j                  d   kD  rt        d«      ‚t        j                   |||f«      }t#        t$        j&                  t(        j*                     |«      }|j                  d	   d
k(  r|dd…dd…df   n%t)        j,                  ||f|j.                  ¬«      dz  }t        j0                  ||z  «      }	| |||z   …|||z   …f   }
|	j3                  t(        j4                  «      dz  }t        j0                  d|dt(        j6                  f   z
  |
z  |dt(        j6                  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.
        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.
        ValueError: For invalid opacity or rectangle dimensions.
    zImage path ('z') does not exist.g        g      ð?z$Opacity must be between 0.0 and 1.0.r   r   zInvalid rectangle dimensions.r   é   Né   )Údtypeéÿ   g     ào@.)Ú
isinstanceÚstrÚosÚpathÚexistsÚFileNotFoundErrorr   ÚimreadÚIMREAD_UNCHANGEDÚ
ValueErrorÚintrI   rJ   r6   r7   ÚshapeÚresizer   ÚnptÚNDArrayÚnpÚuint8Úonesra   ÚconvertScaleAbsÚastypeÚfloat32Únewaxis)r   Úimager%   r   Úrect_xÚrect_yÚ
rect_widthÚrect_heightÚalpha_channelÚalpha_scaledÚ	scene_roiÚalpha_floatÚblended_rois                r   Ú
draw_imager‚   -  s5  € ô0 �%œÔÜ�w‰w�~‰~˜eÔ$Ü# m°E°7Ð:LÐ$MÓNÐNÜ—
‘
˜5¤#×"6Ñ"6Ó7ˆð �'Ô ˜SÒ ÜÐ?Ó@Ð@ð !ÜÐ?Ó@Ð@ä�—‘‹[€FÜ�—‘‹[€FÜ�T—Z‘Z“€JÜ�d—k‘kÓ"€Kð 	�Š
Ø�AŠ:Ø�JÑ §¡¨Q¡Ò/Ø�KÑ %§+¡+¨a¡.Ò0äÐ8Ó9Ð9ô �J‰J�u˜z¨;Ð7Ó8€EÜ”—‘œRŸX™XÑ&¨Ó.€Eð �;‰;�q‰>˜QÒð 	Ša’�AˆgŠä�W‰W�k :Ð.°e·k±kÔBÀSÑHð ô
 ×&Ñ& }°wÑ'>Ó?€Lð �f˜v¨Ñ3Ð3°V¸fÀzÑ>QÐ5QÐQÑR€IØ×%Ñ%¤b§j¡jÓ1°EÑ9€KÜ×%Ñ%Ø	
ˆ[˜œbŸj™j˜Ñ)Ñ	)¨YÑ6Ø
�cœ2Ÿ:™:�oÑ
&¨ªq²!°R°a°R¨x©Ñ
8ñ	9ó€Kð JU€Eˆ&�6˜KÑ'Ð
'¨°&¸:Ñ2EÐ)EÐ
EÑFà€Lr   c                ó   — 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?©r/   ©Úresolution_whs    r   Úcalculate_optimal_text_scaler‡   s  s   € ô, ˆ}Ó Ñ$Ð$r   c                ó"   — t        | «      dk  ryy)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   r_   r„   r…   s    r   Ú calculate_optimal_line_thicknessr‰   Œ  s   € ô, ˆ=Ó˜DÒ ØØr   )r   únpt.NDArray[np.uint8]r   r   r   r   r   r   r   rl   ÚreturnrŠ   )
r   rŠ   r   r   r   r   r   rl   r‹   rŠ   )
r   rŠ   r   r   r   r   r%   Úfloatr‹   rŠ   )
r   rŠ   r   r   r   r   r1   rl   r‹   rŠ   )
r   rŠ   r?   únpt.NDArray[np.int_]r   r   r   rl   r‹   rŠ   )
r   rŠ   r?   r�   r   r   r%   rŒ   r‹   rŠ   )r   rŠ   rF   rd   rQ   r   rR   r   rS   rŒ   rT   rl   rU   rl   rV   rl   rW   zColor | Noner‹   rŠ   )
r   rŠ   rx   zstr | npt.NDArray[np.uint8]r%   rŒ   r   r   r‹   rŠ   )r†   útuple[int, int]r‹   rŒ   )r†   rŽ   r‹   rl   )Ú
__future__r   re   Útypingr   r   Únumpyrq   Únumpy.typingro   Úsupervision.draw.colorr   Úsupervision.geometry.corer   r   ÚROBOFLOWr   r   r'   r;   r@   rC   ÚBLACKÚFONT_HERSHEY_SIMPLEXr]   r‚   r‡   r‰   © r   r   ú<module>r™      sl  ðÝ "ã 	Ý ã 
Û Ý å (ß 1ð —>‘>ØðØ ðàðð 
ðð ð	ð
 ðð óðB —>‘>Øð	Ø ðà
ðð ðð ð	ð
 óð> —>‘>Øð	'Ø ð'à
ð'ð ð'ð ð	'ð
 ó'ðT1Ø ð1à
ð1ð ð1ð ð	1ð
 ó1ðn —>‘>Øð	Ø ðà!ðð ðð ð	ð
 óð4 —>‘>Øð	Ø ðà!ðð ðð ð	ð
 óðB Ÿ™ØØØØ×-Ñ-Ø%)ðPØ ðPà
ðPð ðPð ð	Pð
 ðPð ðPð ðPð ðPð #ðPð óPðfCØ ðCà&ðCð ðCð ð	Cð
 óCóL%ô2r   