o
    e                     @   sR   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 G dd dZdS )    )ListOptionalUnionN)
Detections)ColorColorPalettec                   @   s   e Zd ZdZe de dddfdeeef de	ded	e
d
e	de	fddZ		ddejdedeee  dedejf
ddZdS )BoxAnnotatora  
    A class for drawing bounding boxes on an image using detections provided.

    Attributes:
        color (Union[Color, ColorPalette]): The color to draw the bounding box,
            can be a single color or a color palette
        thickness (int): The thickness of the bounding box lines, default is 2
        text_color (Color): The color of the text on the bounding box, default is white
        text_scale (float): The scale of the text on the bounding box, default is 0.5
        text_thickness (int): The thickness of the text on the bounding box,
            default is 1
        text_padding (int): The padding around the text on the bounding box,
            default is 5

       g      ?   
   color	thickness
text_color
text_scaletext_thicknesstext_paddingc                 C   s(   || _ || _|| _|| _|| _|| _d S )N)r   r   r   r   r   r   )selfr   r   r   r   r   r    r   M/var/www/myenv/lib/python3.10/site-packages/supervision/detection/annotate.py__init__   s   	
zBoxAnnotator.__init__NFscene
detectionslabels
skip_labelreturnc                 C   sr  t j}tt|D ]}|j| t\}}}	}
|jdur!|j| nd}|dur)|n|}t| j	t
r7| j	|n| j	}t j|||f|	|
f| | jd |rNq	|du sZt|t|kr]| n|| }t j||| j| jdd \}}|| j }|| j }|}|d| j  | }|d| j  | }|}t j|||f||f| t jd t j||||f|| j| j | jt jd q	|S )a3  
        Draws bounding boxes on the frame using the detections provided.

        Args:
            scene (np.ndarray): The image on which the bounding boxes will be drawn
            detections (Detections): The detections for which the
                bounding boxes will be drawn
            labels (Optional[List[str]]): An optional list of labels
                corresponding to each detection. If `labels` are not provided,
                corresponding `class_id` will be used as label.
            skip_label (bool): Is set to `True`, skips bounding box label annotation.
        Returns:
            np.ndarray: The image with the bounding boxes drawn on it

        Example:
            ```python
            >>> import supervision as sv

            >>> classes = ['person', ...]
            >>> image = ...
            >>> detections = sv.Detections(...)

            >>> box_annotator = sv.BoxAnnotator()
            >>> labels = [
            ...     f"{classes[class_id]} {confidence:0.2f}"
            ...     for _, _, confidence, class_id, _
            ...     in detections
            ... ]
            >>> annotated_frame = box_annotator.annotate(
            ...     scene=image.copy(),
            ...     detections=detections,
            ...     labels=labels
            ... )
            ```
        N)imgpt1pt2r   r   )textfontFace	fontScaler   r   r	   )r   r   orgr   r    r   r   lineType)cv2FONT_HERSHEY_SIMPLEXrangelenxyxyastypeintclass_id
isinstancer   r   by_idx	rectangleas_bgrr   getTextSizer   r   r   FILLEDputTextr   as_rgbLINE_AA)r   r   r   r   r   fontix1y1x2y2r*   idxr   r   
text_widthtext_heighttext_xtext_ytext_background_x1text_background_y1text_background_x2text_background_y2r   r   r   annotate+   sn   *



zBoxAnnotator.annotate)NF)__name__
__module____qualname____doc__r   defaultr   blackr   r)   floatr   npndarrayr   r   r   strboolrC   r   r   r   r   r   
   sD    


r   )typingr   r   r   r#   numpyrK   supervision.detection.corer   supervision.draw.colorr   r   r   r   r   r   r   <module>   s    