a
    yfX                     @   sV  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlZd dlmZ d dlZd dlZd dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZ d dlm Z m!Z!m"Z"m#Z# d dl$m%Z% G d	d
 d
Z&e& Z'G dd dZ(e e deddfddZ)eddddddfddZ*eej+d ej,ddej+d ej-dej+dej,dddddddddfe
ej.ej/f e
ej.ej/f e
ej.ej/f e
ej.ej/f e	e
ej.ej/f  e
ej.ej/f e
ej.ej/f e	ee0  e0e	ee1e0f  e	e e1e1e2e3e	ej/ ddd Z4e d6d"d#Z5d7d(d)Z6d8d+d,Z7d9d.d/Z8d:d0d1Z9d2ed3fd4d5Z:dS );    N)Path)CallableDictListOptionalUnion)Image	ImageDraw	ImageFont)__version__)
IS_JUPYTERLOGGER	TryExceptopsplt_settingsthreaded)
check_fontcheck_requirementscheck_versionis_ascii)increment_pathc                   @   s.   e Zd ZdZdd Zd
ddZedd Zd	S )Colorsa  
    Ultralytics color palette https://docs.ultralytics.com/reference/utils/plotting/#ultralytics.utils.plotting.Colors.

    This class provides methods to work with the Ultralytics color palette, including converting hex color codes to
    RGB values.

    Attributes:
        palette (list of tuple): List of RGB color values.
        n (int): The number of colors in the palette.
        pose_palette (np.ndarray): A specific color palette array with dtype np.uint8.

    ## Ultralytics Color Palette

    | Index | Color                                                             | HEX       | RGB               |
    |-------|-------------------------------------------------------------------|-----------|-------------------|
    | 0     | <i class="fa-solid fa-square fa-2xl" style="color: #042aff;"></i> | `#042aff` | (4, 42, 255)      |
    | 1     | <i class="fa-solid fa-square fa-2xl" style="color: #0bdbeb;"></i> | `#0bdbeb` | (11, 219, 235)    |
    | 2     | <i class="fa-solid fa-square fa-2xl" style="color: #f3f3f3;"></i> | `#f3f3f3` | (243, 243, 243)   |
    | 3     | <i class="fa-solid fa-square fa-2xl" style="color: #00dfb7;"></i> | `#00dfb7` | (0, 223, 183)     |
    | 4     | <i class="fa-solid fa-square fa-2xl" style="color: #111f68;"></i> | `#111f68` | (17, 31, 104)     |
    | 5     | <i class="fa-solid fa-square fa-2xl" style="color: #ff6fdd;"></i> | `#ff6fdd` | (255, 111, 221)   |
    | 6     | <i class="fa-solid fa-square fa-2xl" style="color: #ff444f;"></i> | `#ff444f` | (255, 68, 79)     |
    | 7     | <i class="fa-solid fa-square fa-2xl" style="color: #cced00;"></i> | `#cced00` | (204, 237, 0)     |
    | 8     | <i class="fa-solid fa-square fa-2xl" style="color: #00f344;"></i> | `#00f344` | (0, 243, 68)      |
    | 9     | <i class="fa-solid fa-square fa-2xl" style="color: #bd00ff;"></i> | `#bd00ff` | (189, 0, 255)     |
    | 10    | <i class="fa-solid fa-square fa-2xl" style="color: #00b4ff;"></i> | `#00b4ff` | (0, 180, 255)     |
    | 11    | <i class="fa-solid fa-square fa-2xl" style="color: #dd00ba;"></i> | `#dd00ba` | (221, 0, 186)     |
    | 12    | <i class="fa-solid fa-square fa-2xl" style="color: #00ffff;"></i> | `#00ffff` | (0, 255, 255)     |
    | 13    | <i class="fa-solid fa-square fa-2xl" style="color: #26c000;"></i> | `#26c000` | (38, 192, 0)      |
    | 14    | <i class="fa-solid fa-square fa-2xl" style="color: #01ffb3;"></i> | `#01ffb3` | (1, 255, 179)     |
    | 15    | <i class="fa-solid fa-square fa-2xl" style="color: #7d24ff;"></i> | `#7d24ff` | (125, 36, 255)    |
    | 16    | <i class="fa-solid fa-square fa-2xl" style="color: #7b0068;"></i> | `#7b0068` | (123, 0, 104)     |
    | 17    | <i class="fa-solid fa-square fa-2xl" style="color: #ff1b6c;"></i> | `#ff1b6c` | (255, 27, 108)    |
    | 18    | <i class="fa-solid fa-square fa-2xl" style="color: #fc6d2f;"></i> | `#fc6d2f` | (252, 109, 47)    |
    | 19    | <i class="fa-solid fa-square fa-2xl" style="color: #a2ff0b;"></i> | `#a2ff0b` | (162, 255, 11)    |

    ## Pose Color Palette

    | Index | Color                                                             | HEX       | RGB               |
    |-------|-------------------------------------------------------------------|-----------|-------------------|
    | 0     | <i class="fa-solid fa-square fa-2xl" style="color: #ff8000;"></i> | `#ff8000` | (255, 128, 0)     |
    | 1     | <i class="fa-solid fa-square fa-2xl" style="color: #ff9933;"></i> | `#ff9933` | (255, 153, 51)    |
    | 2     | <i class="fa-solid fa-square fa-2xl" style="color: #ffb266;"></i> | `#ffb266` | (255, 178, 102)   |
    | 3     | <i class="fa-solid fa-square fa-2xl" style="color: #e6e600;"></i> | `#e6e600` | (230, 230, 0)     |
    | 4     | <i class="fa-solid fa-square fa-2xl" style="color: #ff99ff;"></i> | `#ff99ff` | (255, 153, 255)   |
    | 5     | <i class="fa-solid fa-square fa-2xl" style="color: #99ccff;"></i> | `#99ccff` | (153, 204, 255)   |
    | 6     | <i class="fa-solid fa-square fa-2xl" style="color: #ff66ff;"></i> | `#ff66ff` | (255, 102, 255)   |
    | 7     | <i class="fa-solid fa-square fa-2xl" style="color: #ff33ff;"></i> | `#ff33ff` | (255, 51, 255)    |
    | 8     | <i class="fa-solid fa-square fa-2xl" style="color: #66b2ff;"></i> | `#66b2ff` | (102, 178, 255)   |
    | 9     | <i class="fa-solid fa-square fa-2xl" style="color: #3399ff;"></i> | `#3399ff` | (51, 153, 255)    |
    | 10    | <i class="fa-solid fa-square fa-2xl" style="color: #ff9999;"></i> | `#ff9999` | (255, 153, 153)   |
    | 11    | <i class="fa-solid fa-square fa-2xl" style="color: #ff6666;"></i> | `#ff6666` | (255, 102, 102)   |
    | 12    | <i class="fa-solid fa-square fa-2xl" style="color: #ff3333;"></i> | `#ff3333` | (255, 51, 51)     |
    | 13    | <i class="fa-solid fa-square fa-2xl" style="color: #99ff99;"></i> | `#99ff99` | (153, 255, 153)   |
    | 14    | <i class="fa-solid fa-square fa-2xl" style="color: #66ff66;"></i> | `#66ff66` | (102, 255, 102)   |
    | 15    | <i class="fa-solid fa-square fa-2xl" style="color: #33ff33;"></i> | `#33ff33` | (51, 255, 51)     |
    | 16    | <i class="fa-solid fa-square fa-2xl" style="color: #00ff00;"></i> | `#00ff00` | (0, 255, 0)       |
    | 17    | <i class="fa-solid fa-square fa-2xl" style="color: #0000ff;"></i> | `#0000ff` | (0, 0, 255)       |
    | 18    | <i class="fa-solid fa-square fa-2xl" style="color: #ff0000;"></i> | `#ff0000` | (255, 0, 0)       |
    | 19    | <i class="fa-solid fa-square fa-2xl" style="color: #ffffff;"></i> | `#ffffff` | (255, 255, 255)   |

    !!! note "Ultralytics Brand Colors"

        For Ultralytics brand colors see [https://www.ultralytics.com/brand](https://www.ultralytics.com/brand). Please use the official Ultralytics colors for all marketing materials.
    c                    s   d} fdd|D  _ t j  _tjg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg dg dg dg dgtjd _dS )zEInitialize colors as hex = matplotlib.colors.TABLEAU_COLORS.values().)Z042AFFZ0BDBEBZF3F3F3Z00DFB7Z111F68ZFF6FDDZFF444FZCCED00Z00F344ZBD00FFZ00B4FFZDD00BAZ00FFFFZ26C000Z01FFB3Z7D24FFZ7B0068ZFF1B6CZFC6D2FZA2FF0Bc                    s   g | ]}  d | qS )#)hex2rgb).0cself V/var/www/html/django/DPS/env/lib/python3.9/site-packages/ultralytics/utils/plotting.py
<listcomp>p       z#Colors.__init__.<locals>.<listcomp>)      r   )r"      3   )r"      f   )   r(   r   )r"   r$   r"   )r$      r"   )r"   r'   r"   )r"   r%   r"   )r'   r&   r"   )r%   r$   r"   )r"   r$   r$   )r"   r'   r'   )r"   r%   r%   )r$   r"   r$   )r'   r"   r'   )r%   r"   r%   r   r"   r   )r   r   r"   )r"   r   r   r"   r"   r"   dtypeN)palettelennnparrayuint8pose_palette)r   Zhexsr   r   r   __init__X   s6    zColors.__init__Fc                 C   s2   | j t|| j  }|r.|d |d |d fS |S )z'Converts hex color codes to RGB values.      r   )r.   intr0   )r   iZbgrr   r   r   r   __call__   s    zColors.__call__c                    s   t  fdddD S )z@Converts hex color codes to RGB values (i.e. default PIL order).c                 3   s,   | ]$}t  d | d | d  dV  qdS )r7   r6      Nr8   r   r9   hr   r   	<genexpr>   r!   z!Colors.hex2rgb.<locals>.<genexpr>)r   r6      tupler>   r   r>   r   r      s    zColors.hex2rgbN)F)__name__
__module____qualname____doc__r5   r:   staticmethodr   r   r   r   r   r      s
   B4
r   c                   @   s  e Zd ZdZdIddZdJd
dZdKddZdLddZdMddZdNddZ	dOddZ
dPddZdQd!d"Zd#d$ Zd%d& ZdRd'd(ZdSd*d+ZdTd,d-ZdUd/d0ZdVd2d3ZdWd5d6Zd7d8 Zd9d: Zed;d< ZdXd=d>ZdYd@dAZdZdBdCZdDdE Zd[dGdHZdS )\	Annotatora7  
    Ultralytics Annotator for train/val mosaics and JPGs and predictions annotations.

    Attributes:
        im (Image.Image or numpy array): The image to annotate.
        pil (bool): Whether to use PIL or cv2 for drawing annotations.
        font (ImageFont.truetype or ImageFont.load_default): Font used for text annotations.
        lw (float): Line width for drawing.
        skeleton (List[List[int]]): Skeleton structure for keypoints.
        limb_color (List[int]): Color palette for limbs.
        kpt_color (List[int]): Color palette for keypoints.
    N	Arial.ttfFabcc           
         s  t | }t|tj}|p |p | _|pLttt|r8|jn|jd d d _	 jr|r^|nt
| _t j _zHt|rdn|}|pttt jjd d d}	tt||	 _W n ty   t  _Y n0 ttdr fdd j_nH|jjsJ d	|jjr|n|  _t j	d
 d
 _ j	d  _ddgddgddgddgddgddgddgddgddgddgddgddgddgd
dgd
dgddgddgddgddgg _ t!j"g d  _#t!j"g d  _$h d _%h d _&dS )zjInitialize the Annotator class with image and line width along with color palette for keypoints and limbs.r6   g~jth?zArial.Unicode.ttfgQ?   z9.2.0c                    s    j | dd S )Nr6   rA   )fontZgetbbox)xr   r   r   <lambda>   r!   z$Annotator.__init__.<locals>.<lambda>zOImage not contiguous. Apply np.ascontiguousarray(im) to Annotator input images.r7      r;                        	   
      rA      )rX   rX   rX   rX   rV   rV   rV   r   r   r   r   r   r;   r;   r;   r;   r;   r;   r;   )r;   r;   r;   r;   r;   r   r   r   r   r   r   rX   rX   rX   rX   rX   rX   >	   )r"   r"   r   )   r\   r\   )rZ   r"      )   o   r"   )D   r\   r   )   r"   r7         rZ   )      r   )r      r)   >   )h   r   {   )r"   *   rA   )/   m      )r      &   )r"   r      )O   r`   r"   )r"      r   )   r   r^   )r"   $   }   rh      rR   )l      r"   N)'r   
isinstancer   pilmaxroundsumsizeshapelw	fromarrayimr	   Drawdrawr   r
   ZtruetypestrrM   	ExceptionZload_defaultr   pil_versiongetsizedata
contiguousflagsZ	writeablecopytfsfskeletoncolorsr4   
limb_color	kpt_colordark_colorslight_colors)
r   r   
line_width	font_sizerM   r{   exampleZ	non_asciiZinput_is_pilr   r   r   r   r5      sV    
,"

zAnnotator.__init__r#   r#   r#   r+   c                 C   s$   || j v rdS || jv rdS |S dS )z,Assign text color based on background color.rv   r+   N)r   r   )r   color	txt_colorr   r   r   get_txt_color   s
    

zAnnotator.get_txt_color r6   c              
   C   s  t |dkr,tdt | d |dd }t|d |d  d t|d |d  d  }}tt|tj| jd | jd }t|d d |d d  d	 d | }	t	| j
||f|	|d
 ||d d  }
||d d  }tj| j
t||
|ftj| jd | ||| jtjd dS )a  
        Draws a label with a background circle centered within a given bounding box.

        Args:
            box (tuple): The bounding box coordinates (x1, y1, x2, y2).
            label (str): The text label to be displayed.
            color (tuple, optional): The background color of the rectangle (B, G, R).
            txt_color (tuple, optional): The color of the text (R, G, B).
            margin (int, optional): The margin between the text and the rectangle border.
        rP   zLength of label is zF, initial 3 label characters will be considered for circle annotation!Nr   r6   r7   g333333?      ?lineType)r/   printr8   cv2getTextSizer   FONT_HERSHEY_SIMPLEXr   r   circler   putTextr   LINE_AA)r   boxlabelr   r   marginx_centery_center	text_sizeZrequired_radiustext_xtext_yr   r   r   circle_label   s*    2"(
zAnnotator.circle_labelr[   c              
   C   s   t |d |d  d t |d |d  d  }}t|tj| jd | jd }||d d  }	||d d  }
|	| }|
|d  | }|	|d  | }|
| }t| j||f||f|d tj| j||	|
ftj| jd | 	||| jtj
d dS )	a  
        Draws a label with a background rectangle centered within a given bounding box.

        Args:
            box (tuple): The bounding box coordinates (x1, y1, x2, y2).
            label (str): The text label to be displayed.
            color (tuple, optional): The background color of the rectangle (B, G, R).
            txt_color (tuple, optional): The color of the text (R, G, B).
            margin (int, optional): The margin between the text and the rectangle border.
        r   r6   r7   rP   g?r   r   N)r8   r   r   r   r   r   	rectangler   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   rect_x1rect_y1rect_x2rect_y2r   r   r   
text_label#  s&    2
zAnnotator.text_labelc              
   C   s  |  ||}t|tjr | }| js0t|sd|r\|d }| jjdd |D | j	|d n$|d |d f}| jj
|| j	|d |r| j|\}}|d |k}	|d | jjd | kr| jjd | |d f}| jj
|d |	r|d | n|d |d | d |	r|d d n|d | d f|d | jj|d |	rJ|d | n|d f||| jd n~|rdd |d D }t| jtj|td	gd
|| j	 nNt|d t|d ft|d t|d f }}
tj
| j||
|| j	tjd |rtj|d| j| jdd \}}|d7 }|d |k}	|d | jjd | krX| jjd | |d f}|d | |	rt|d | n
|d | f}
t
| j||
|dtj tj| j||d |	r|d d n|d | d fd| j|| jtjd dS )a  
        Draws a bounding box to image with label.

        Args:
            box (tuple): The bounding box coordinates (x1, y1, x2, y2).
            label (str): The text label to be displayed.
            color (tuple, optional): The background color of the rectangle (B, G, R).
            txt_color (tuple, optional): The color of the text (R, G, B).
            rotated (bool, optional): Variable used to check if task is OBB
        r   c                 S   s   g | ]}t |qS r   rB   r   br   r   r   r    Y  r!   z'Annotator.box_label.<locals>.<listcomp>widthoutliner7   fillr   rM   c                 S   s   g | ]}t |qS r   r<   r   r   r   r   r    j  r!   r,   Tr6   rP   	thicknessr   	fontScaler   r   N)r   rz   torchTensortolistr{   r   r   Zpolygonr   r   rM   r   r   r   textr   	polylinesr1   asarrayr8   r   r   r   r   r   r   )r   r   r   r   r   rotatedp1wr?   outsidep2r   r   r   	box_labelH  sT     L8$2*(zAnnotator.box_labelr   c                 C   sH  | j rt| j | _t|dkrL|ddd  	 d | jdd< |j
|j
krd||j
}tj||j
tjdd }|ddddf }|d}|||  }d||  d}|jdd	j}|jdgd
}|ddd }||d  | }|d }	|	  	 }
|r|
nt|
| jj| jdd< | j rD| | j dS )a  
        Plot masks on image.

        Args:
            masks (tensor): Predicted masks on cuda, shape: [n, h, w]
            colors (List[List[Int]]): Colors for predicted masks, [[r, g, b] * n]
            im_gpu (tensor): Image is in cuda, shape: [3, h, w], range: [0, 1]
            alpha (float): Mask transparency: 0.0 fully transparent, 1.0 opaque
            retina_masks (bool): Whether to use high resolution masks or not. Defaults to False.
        r   r7   r6   r"   N)devicer-   g     o@rP   dim)dimsr   )r{   r1   r   r   r   r/   Zpermuter   cpunumpyr   tor   Ztensorfloat32	unsqueezeZcumprodr|   valuesflipbyter   Zscale_imager   r   )r   masksr   Zim_gpualphaZretina_masksZmasks_colorZinv_alpha_masksmcsZim_maskZ
im_mask_npr   r   r   r     s(    (
$zAnnotator.masks  r   T      ?c                 C   s  |dur|n| j }| jr*t| j | _|j\}}|dkoB|dv }	||	M }t|D ]\}
}|px|	rr| j|
 	 nt
|
}|d |d  }}||d  dkrT||d  dkrTt|dkr|d }||k rqTtj| jt|t|f||dtjd	 qT|r|jd }t| jD ]\}
}t||d d df t||d d df f}t||d d df t||d d df f}|dkr||d d df }||d d df }||k s||k rq|d |d  dks|d |d  dks|d dk s|d dk rq|d |d  dks|d |d  dks|d dk s|d dk rXqtj| j|||pv| j|
 	 tt| j d tjd
 q| jr| | j dS )a  
        Plot keypoints on the image.

        Args:
            kpts (torch.Tensor): Keypoints, shape [17, 3] (x, y, confidence).
            shape (tuple, optional): Image shape (h, w). Defaults to (640, 640).
            radius (int, optional): Keypoint radius. Defaults to 5.
            kpt_line (bool, optional): Draw lines between keypoints. Defaults to True.
            conf_thres (float, optional): Confidence threshold. Defaults to 0.25.
            kpt_color (tuple, optional): Keypoint color (B, G, R). Defaults to None.

        Note:
            - `kpt_line=True` currently only supports human pose plotting.
            - Modifies self.im in-place.
            - If self.pil is True, converts image to numpy array and back to PIL.
        NrR   >   r6   rP   r   r7   rP   r6   r   r   r   )r   r{   r1   r   r   r   r   	enumerater   r   r   r/   r   r   r8   r   r   liner   ceilr   )r   kptsr   radiusZkpt_line
conf_thresr   ZnkptndimZis_poser9   kZcolor_kx_coordy_coordconfskZpos1pos2Zconf1Zconf2r   r   r   r     sN    
 (
00
HH
zAnnotator.kptsr7   c                 C   s   | j |||| dS )z"Add rectangle to image (PIL-only).N)r   r   )r   xyr   r   r   r   r   r   r     s    zAnnotator.rectangletopc              
   C   s  |dkr,| j |\}}|d  d| 7  < | jr|r| j |\}}| jj|d |d |d | d |d | d f|d d}d|v r|d}| j |\}	}|D ]*}
| jj||
|| j d |d  |7  < qn| jj|||| j d n|rltj|d| j	| j
dd \}}|d	7 }|d |k}|d | |rB|d | n
|d | f}t| j|||d
tj d}tj| j||d| j	|| j
tjd dS )z'Adds text to an image using PIL or cv2.bottomr7   r   r   r+   
r   r   rP   r   r   N)rM   r   r{   r   r   splitr   r   r   r   r   r   r   r   )r   r   r   r   anchor	box_styler   r?   lines_r   r   r   r   r   r   r     s.    8
*zAnnotator.textc                 C   s.   t |tjr|nt|| _t| j| _dS )z"Update self.im from a numpy array.N)rz   r   r   r   r	   r   r   )r   r   r   r   r   r     s    zAnnotator.fromarrayc                 C   s   t | jS )z Return annotated image as array.)r1   r   r   r   r   r   r   result	  s    zAnnotator.resultc              
   C   s   t t| jddddf }tr|td zddlm} || W q t	yx } zt
d|  W Y d}~qd}~0 0 n|j|d dS )	zShow the annotated image..Nr   ipythonr   )displayz.Unable to display image in Jupyter notebooks: )title)r   r   r1   r   r   r   r   IPython.displayr   ImportErrorr   warningshow)r   r   r   r   er   r   r   r     s     (zAnnotator.show	image.jpgc                 C   s   t |t| j dS )z'Save the annotated image to 'filename'.N)r   Zimwriter1   r   r   )r   filenamer   r   r   save  s    zAnnotator.savec                 C   s*   |\}}}}|| }|| }|||| fS )z
        Calculate the area of a bounding box.

        Args:
            bbox (tuple): Bounding box coordinates in the format (x_min, y_min, x_max, y_max).

        Returns:
            angle (degree): Degree value of angle between three points
        r   )r   ZbboxZx_minZy_minZx_maxZy_maxr   heightr   r   r   get_bbox_dimension   s    
zAnnotator.get_bbox_dimensionr*   c                 C   sV   t j| jtj|tjdgd||d |D ](}t | j|d |d f|d |d q(dS )	z
        Draw region line.

        Args:
            reg_pts (list): Region Points (for line 2 points, for region 4 points)
            color (tuple): Region Color value
            thickness (int): Region area thickness value
        r,   TZisClosedr   r   r   r7   r6   r   N)r   r   r   r1   r2   int32r   )r   Zreg_ptsr   r   pointr   r   r   draw_region/  s    	$zAnnotator.draw_regionr"   r   r"   c                 C   sh   t |t jd}tj| j|gd||d t| jt	|d d t	|d d f|d |d dS )	z
        Draw centroid point and track trails.

        Args:
            track (list): object tracking points for trails display
            color (tuple): tracks line color
            track_thickness (int): track line thickness value
        )r   r7   r6   Fr  r   r   r7   r6   N)
r1   Zhstackastyper  reshaper   r   r   r   r8   )r   trackr   Ztrack_thicknesspointsr   r   r   draw_centroid_and_tracks>  s    	z"Annotator.draw_centroid_and_tracksr   r   r   c              
   C   s   dd |D }dd |D }t |t| }t |t| }tj|d| j| jdd }	|	d }
|	d }|
d }|d }||d  ||d  f}||d  ||d  f}t| j|||d	 ||
d  }||d  }tj| j|||fd| j|| jtj	d
 dS )au  
        Displays queue counts on an image centered at the points with customizable font size and colors.

        Args:
            label (str): queue counts label
            points (tuple): region points for center point calculation to display text
            region_color (tuple): RGB queue region color.
            txt_color (tuple): RGB text display color.
        c                 S   s   g | ]}|d  qS )r   r   r   r  r   r   r   r    U  r!   z2Annotator.queue_counts_display.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )r7   r   r  r   r   r   r    V  r!   r   r   r7      r6   r   )r   r   r   r   N)
r~   r/   r   r   r   r   r   r   r   r   )r   r   r  Zregion_colorr   Zx_valuesZy_valuesZcenter_xZcenter_yr   
text_widthZtext_heightZ
rect_widthZrect_heightZrect_top_leftZrect_bottom_rightr   r   r   r   r   queue_counts_displayK  s0    
zAnnotator.queue_counts_displayc              
   C   s   t j|d| j| jdd }||d d  }	||d d  }
|	| }|
|d  | }|	|d  | }|
| }t |||f||f|d t j|||	|
fd| j|| jt jd dS )a  
        Display the bounding boxes labels in parking management app.

        Args:
            im0 (ndarray): inference image
            text (str): object/class name
            txt_color (tuple): display color for text foreground
            bg_color (tuple): display color for text background
            x_center (float): x position center point for bounding box
            y_center (float): y position center point for bounding box
            margin (int): gap between text and rectangle for better display
        r   r   r6   r7   r   r   N)r   r   r   r   r   r   r   )r   im0r   r   bg_colorr   r   r   r   r   r   r   r   r   r   r   r   r   display_objects_labelss  s    z Annotator.display_objects_labelsc                 C   s:  t |jd d }t |jd d }d}| D ]\}	}
|	 d|
 }t|d| j| jd }|d dk sx|d dk r|d}|jd |d  |d  | }||d  |d  | }||d  }||d  |d  }||d  |d  }||d  }t|||f||f|d	 tj||||fd| j|| jtj	d
 |}q0dS )at  
        Display the overall statistics for parking lots.

        Args:
            im0 (ndarray): inference image
            text (dict): labels dictionary
            txt_color (tuple): display color for text foreground
            bg_color (tuple): display color for text background
            margin (int): gap between text and rectangle for better display
        r7   g{Gz?r   {Gz?: r[   )r[   r[   r6   r   r   N)
r8   r   itemsr   r   r   r   r   r   r   )r   r  r   r   r  r   Zhorizontal_gapZvertical_gapZtext_y_offsetr   valuetxtr   r   r   r   r   r   r   r   r   r   display_analytics  s"    $zAnnotator.display_analyticsc                 C   s   t | t |t |  } }}t |d |d  |d |d  t | d |d  | d |d   }t |d t j }|dkrd| }|S )a1  
        Calculate the pose angle for object.

        Args:
            a (float) : The value of pose point a
            b (float): The value of pose point b
            c (float): The value o pose point c

        Returns:
            angle (degree): Degree value of angle between three points
        r7   r   g     f@ih  )r1   r2   Zarctan2abspi)ar   r   radiansangler   r   r   estimate_pose_angle  s    "HzAnnotator.estimate_pose_anglec              	   C   s   |du rg d}t |D ]\}}||v r|d |d  }}	||d  dkr|	|d  dkrt|dkrx|d }
|
|k rxqtj| jt|t|	f|ddtjd	 q| jS )
a  
        Draw specific keypoints for gym steps counting.

        Args:
            keypoints (list): Keypoints data to be plotted.
            indices (list, optional): Keypoint indices to be plotted. Defaults to [2, 5, 7].
            shape (tuple, optional): Image size for model inference. Defaults to (640, 640).
            radius (int, optional): Keypoint radius. Defaults to 2.
            conf_thres (float, optional): Confidence threshold for keypoints. Defaults to 0.25.

        Returns:
            (numpy.ndarray): Image with drawn keypoints.

        Note:
            Keypoint format: [x, y] or [x, y, confidence].
            Modifies self.im in-place.
        N)r6   r[   rV   r   r7   rP   r6   r*   r   r   )r   r/   r   r   r   r8   r   )r   Z	keypointsindicesr   r   r   r9   r   r   r   r   r   r   r   draw_specific_points  s     (zAnnotator.draw_specific_pointsrv   c              	   C   s@  d|dd| d|   }}}t |d| j| j\\}}}	t|d t|d f}
|
d |
d | d f}|d |d | jd  f}t | j||d |d  |d |d  f|d	 t | j||
d| j|| j t |d| j| j\\}}}	|
d |
d | d
 f}|d |d |d  d f}|d |d | j f}t | j||d |d  |d |d  f|d	 t | j||d| j|| j t |d| j| j\\}}}	t|d t|d | | d f}|d |d | d f}|d |d f}t | j||d |d  |d |d  f|d	 t | j||d| j|| j dS )a  
        Plot the pose angle, count value and step stage.

        Args:
            angle_text (str): angle value for workout monitoring
            count_text (str): counts value for workout monitoring
            stage_text (str): stage decision for workout monitoring
            center_kpt (list): centroid pose index for workout monitoring
            color (tuple): text background color for workout monitoring
            txt_color (tuple): text foreground color for workout monitoring
         .2fzSteps : r   r7   r[   rY   r6   r   r  (   N)r   r   r   r   r8   r   r   r   )r   Z
angle_textZ
count_textZ
stage_textZ
center_kptr   r   Zangle_text_widthZangle_text_heightr   Zangle_text_positionZangle_background_positionZangle_background_sizeZcount_text_widthZcount_text_heightZcount_text_positionZcount_background_positionZcount_background_sizeZstage_text_widthZstage_text_heightZstage_text_positionZstage_background_positionZstage_background_sizer   r   r   plot_angle_and_count_and_stage  sZ    $

$
z(Annotator.plot_angle_and_count_and_stagec              	   C   s  |j dkrdS tj| jt|ggd|dd t|d| j| j\}}t	| jt
|d d |d d  d t
|d d |d  d ft
|d d |d d  d t
|d d d f|d |rt| j|t
|d d |d d  t
|d d fd| j|| j dS )	a  
        Function for drawing segmented object in bounding box shape.

        Args:
            mask (np.ndarray): A 2D array of shape (N, 2) containing the contour points of the segmented object.
            mask_color (tuple): RGB color for the contour and label background.
            label (str, optional): Text label for the object. If None, no label is drawn.
            txt_color (tuple): RGB color for the label text.
        r   NTr6   r  rY   r7   r   )r   r   r   r   r1   r  r   r   r   r   r8   r   )r   maskZ
mask_colorr   r   r   r   r   r   r   seg_bbox#  s    

 :2<zAnnotator.seg_bboxc              
   C   s   t d|dd| j| j\\}}}d}d| d d| d f}	t | j||	|d |d d	 |d
 | d	 f}
t | jd|d|
d| jd| jt j t | j|d |d
 |d t 	| j|d d|d t 	| j|d
 d|d dS )aO  
        Plot the distance and line on frame.

        Args:
            pixels_distance (float): Pixels distance between two bbox centroids.
            centroids (list): Bounding box centroids data.
            line_color (tuple): RGB distance line color.
            centroid_color (tuple): RGB bounding box centroid color.
        zPixels Distance: r'  r   )rS      rS   r  r,  r   rY   r7   r+   rP   rU   N)
r   r   r   r   r   r   r   r   r   r   )r   Zpixels_distanceZ	centroidsZ
line_colorZcentroid_colorZtext_width_mZtext_height_mr   top_leftbottom_rightZtext_positionr   r   r   plot_distance_and_line@  s(    
z Annotator.plot_distance_and_linerb   c                 C   s~   t |d |d  d t |d |d  d f}t| j|| jd |d t| j|| jd |d t| j|||| j dS )aL  
        Function for pinpoint human-vision eye mapping and plotting.

        Args:
            box (list): Bounding box coordinates
            center_point (tuple): center point for vision eye view
            color (tuple): object centroid and line color value
            pin_color (tuple): visioneye point color value
        r   r6   r7   rP   r   N)r8   r   r   r   r   r   )r   r   Zcenter_pointr   Z	pin_colorZcenter_bboxr   r   r   	visioneyee  s    
0zAnnotator.visioneye)NNrJ   FrK   )r   r+   )r   r   r+   r6   )r   r   r+   r[   )r   r   r+   F)r   F)r   NTr   N)NNr7   )r+   r   F)N)r  )N)Nr*   r[   )r
  r6   )Nr+   r  )Nr   r6   r   )rv   r+   )r
  Nr+   )rb   r
  )rD   rE   rF   rG   r5   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  rH   r#  r%  r)  r+  r/  r0  r   r   r   r   rI      s8   
I
	
)
%
:
$
<







(

  
H
%rI   r   r   c              	   C   s  ddl }ddl}tjdtdd tjdtd td|d  d	 t|	 d
 }| dd } |j
| g dd}|j|dddtddtddd tj|d dd t  tjdddddd
  }	|	d j|td||d
 d dd}
t|D ]&}|
d j| dd  t|D  q|	d d! dt|  k rHd"k rn n4|	d tt| |	d jt| d#d$d% n|	d d& |j |d'd(|	d ddd) |j |d*d+|	d, ddd) d| ddddf< t!"| d- } t#$tj%d.tj&d/d0 }t'|dd1 | dd1 D ]$\}}t()|j*|d
t|d2 q|	d
 +| |	d
 ,d3 d4D ]&}d5D ]}|	| j-| .d6 qfq^|d }tj|dd t  |r|| dS )7zCPlot training labels including class histograms and box statistics.r   Nignorez&The figure layout has changed to tight)categorymessage)r2  zPlotting labels to z
labels.jpgz... r7   i@B )rN   yr   r  )columnsTautohist2   binsg?)pmax)ZcornerZ	diag_kindkindZdiag_kwsZplot_kwszlabels_correlogram.jpg   dpir6   )rW   rW   Zfigsizetight_layoutr   皙?)r:  Zrwidthc                 S   s   g | ]}|d  qS )r"   r   r   rN   r   r   r   r      r!   zplot_labels.<locals>.<listcomp>Z	instances   Z   rY   )ZrotationfontsizeclassesrN   r4  )rN   r4  axr:  r;  r   r  rP     )rI  rI  rP   r,   r"   i  r   off)r   r7   r6   rP   )r   rightleftr   F)/pandasseabornwarningsfilterwarningsUserWarningFutureWarningr   infor8   r|   Z	DataFrameZpairplotdictpltsavefigclosesubplotsravelr7  r1   ZlinspacerangeZpatchesZ	set_colorr   Z
set_ylabelr/   Z
set_xticksZset_xticklabelslistr   Z
set_xlabelZhistplotr   	xywh2xyxyr   r   Zonesr3   zipr	   r   r   imshowaxisZspinesZset_visible)boxesclsnamessave_diron_plotrM  rN  ncrN   rH  r4  r9   Zimgr   r   sfnamer   r   r   plot_labelsu  sJ    "&$ "rh  zim.jpggRQ?rY   FTc                 C   s<  t | tjst| } t| dd}|r`|ddddf dd d|ddddf< |ddddf | | |ddddf< t	|
 } t| |j} |t| d t| d t| d	 t| d
 dd|rdndf }	|r8|jjddd tt|d}
t|	ddddf j|
ddd |	S )a  
    Save image crop as {file} with crop size multiple {gain} and {pad} pixels. Save and/or return crop.

    This function takes a bounding box and an image, and then saves a cropped portion of the image according
    to the bounding box. Optionally, the crop can be squared, and the function allows for gain and padding
    adjustments to the bounding box.

    Args:
        xyxy (torch.Tensor or list): A tensor or list representing the bounding box in xyxy format.
        im (numpy.ndarray): The input image.
        file (Path, optional): The path where the cropped image will be saved. Defaults to 'im.jpg'.
        gain (float, optional): A multiplicative factor to increase the size of the bounding box. Defaults to 1.02.
        pad (int, optional): The number of pixels to add to the width and height of the bounding box. Defaults to 10.
        square (bool, optional): If True, the bounding box will be transformed into a square. Defaults to False.
        BGR (bool, optional): If True, the image will be saved in BGR format, otherwise in RGB. Defaults to False.
        save (bool, optional): If True, the cropped image will be saved to disk. Defaults to True.

    Returns:
        (numpy.ndarray): The cropped image.

    Example:
        ```python
        from ultralytics.utils.plotting import save_one_box

        xyxy = [50, 50, 150, 150]
        im = cv2.imread("image.jpg")
        cropped_im = save_one_box(xyxy, im, file="cropped.jpg", square=True)
        ```
    r   rA   Nr6   r7   r   )r   r7   )r   rP   )r   r   )r   r6   T)parentsexist_okz.jpg._   )ZqualityZsubsampling)rz   r   r   stackr   	xyxy2xywhviewr|   r   r\  longZ
clip_boxesr   r8   parentmkdirr   r   with_suffixr   r   r  )Zxyxyr   fileZgainpadZsquareZBGRr  r   cropfr   r   r   save_one_box  s    
4,D$rw  r,   )r   r%   z
images.jpgi  r;   r   )images	batch_idxra  bboxesconfsr   r   pathsrg  rb  rd  max_sizemax_subplotsr  r   returnc           -   
      s  t | tjr|    } t |tjr4|  }t |tjrL|  }t |tjrj|  t}t |tjr|  }t |tjr|  }| j\}}}}t	||}t
|d  t
| d dkr| d9 } t
jt | t | dfdt
jd}t|D ]X}t||   t||    }}| | ddd|||| ||| ddf< q
|  t|| }|dk rt|| }t|| }t|t fd	d
||fD }t||   d }t|t|d |d|	d}t|D ]}t||   t||    }}|j|||| || gdddd |rr|j|d |d ft|| jdd dd t|dkr||k}|| d}|du }t|r|| }|dur|| nd}t|rB|ddddf  dkr |dddgf  |9  < |dddgf  |9  < n"|dk rB|dddf  |9  < |d  |7  < |d  |7  < |jd dk}|rt|nt|}t|t
j ! D ]v\} }!||  }"t"|"}#|	r|	#|"|"n|"}"|s||  |kr|r|" n|" d||  d}$|j$|!|$|#|d qnLt|rd|D ]<}"t"|"}#|	rD|	#|"|"n|"}"|j||f|" |#dd q&t|r6|| % }%t|%r|%d  d ks|%d  d kr|%d  |9  < |%d  |9  < n|dk r|%|9 }%|%d  |7  < |%d  |7  < tt|%D ],} |s ||  |kr|j&|%|  |d! qt|r|jd |jd kr`|| }&nN||g }&|' }'t
(|')|'ddfd }(t
j*|&|'dd"}&t
+|&|(kd#d$}&t
,|j-% })tt|&D ]} |s||  |krt"||  }#|&|  j\}*}+|*|ks|+|kr>|&|  t
j},t|,||f},|,t.},n|&|  t.},t/0t1j |)||| ||| ddf |, d% t
2|#d&  |)||| ||| ddf |,< W d   n1 s0    Y  q|3|) q|st
,|j-S |j-4| |
r|
| dS )'a  
    Plot image grid with labels, bounding boxes, masks, and keypoints.

    Args:
        images: Batch of images to plot. Shape: (batch_size, channels, height, width).
        batch_idx: Batch indices for each detection. Shape: (num_detections,).
        cls: Class labels for each detection. Shape: (num_detections,).
        bboxes: Bounding boxes for each detection. Shape: (num_detections, 4) or (num_detections, 5) for rotated boxes.
        confs: Confidence scores for each detection. Shape: (num_detections,).
        masks: Instance segmentation masks. Shape: (num_detections, height, width) or (1, height, width).
        kpts: Keypoints for each detection. Shape: (num_detections, 51).
        paths: List of file paths for each image in the batch.
        fname: Output filename for the plotted image grid.
        names: Dictionary mapping class indices to class names.
        on_plot: Optional callback function to be called after saving the plot.
        max_size: Maximum size of the output image grid.
        max_subplots: Maximum number of subplots in the image grid.
        save: Whether to save the plotted image grid to a file.
        conf_thres: Confidence threshold for displaying detections.

    Returns:
        np.ndarray: Plotted image grid as a numpy array if save is False, None otherwise.

    Note:
        This function supports both tensor and numpy array inputs. It will automatically
        convert tensor inputs to numpy arrays for processing.
    r   r   r7   r"   rP   r,   r6   Nc                 3   s   | ]}t |  V  qd S )Nr<   rC  nsr   r   r@   '  r!   zplot_images.<locals>.<genexpr>r  rY   T)r   r   r{   r   r+   )r   r[   r(  )   r  r  )r   r   r8   rA   g?.).r   ).r7   r   r&  z.1f)r   r   )r   r   g)\(?)r   )r_  g      ?g        g?g333333?)5rz   r   r   r   floatr   r  r8   r   minr1   r   r|   fullr3   rZ  Z	transposemathr   resizerC   rI   r}   r   r   r   namer/   r   Zxywhr2xyxyxyxyr\  r   Zint64r   r   getr   r   r   r~   Zaranger  repeatwherer   r   bool
contextlibsuppressr   r2   r   r  )-rx  ry  ra  rz  r{  r   r   r|  rg  rb  rd  r}  r~  r  r   bsr   r?   r   Zmosaicr9   rN   r4  scalefsZ	annotatoridxrG  labelsr`  r   Zis_obbjr   r   r   r   Zkpts_Zimage_masksnlindexr   mhmwr*  r   r  r   plot_images  s    -
("4
""".


 


$



6Hr  path/to/results.csvc                 C   s  ddl }ddlm} | r"t| jnt|}|rNtjddddd\}	}
g d}nf|rrtjdd	d
dd\}	}
g d}nB|rtjddddd\}	}
g d}ntjddddd\}	}
g d}|
 }
t|	d}t
|sJ d|  d|D ]}z||}dd |jD }|jdddf }t|D ]t\}}|jdd|f d}|
| j||d|jdd	d |
| j|||dddddd |
| j|| dd  q$W q ty } z"td!| d"|  W Y d}~qd}~0 0 q|
d#   |d$ }|	j|d%d& t  |r|| dS )'aR  
    Plot training results from a results CSV file. The function supports various types of data including segmentation,
    pose estimation, and classification. Plots are saved as 'results.png' in the directory where the CSV is located.

    Args:
        file (str, optional): Path to the CSV file containing the training results. Defaults to 'path/to/results.csv'.
        dir (str, optional): Directory where the CSV file is located if 'file' is not provided. Defaults to ''.
        segment (bool, optional): Flag to indicate if the data is for segmentation. Defaults to False.
        pose (bool, optional): Flag to indicate if the data is for pose estimation. Defaults to False.
        classify (bool, optional): Flag to indicate if the data is for classification. Defaults to False.
        on_plot (callable, optional): Callback function to be executed after plotting. Takes filename as an argument.
            Defaults to None.

    Example:
        ```python
        from ultralytics.utils.plotting import plot_results

        plot_results("path/to/results.csv", segment=True)
        ```
    r   Ngaussian_filter1dr6   )rU   rU   Tr@  )r7   rA   r6   rP   rW   )   rU   )r7   r6   rP   rA   r[   rU   rX   rY   rT   rQ   rS   r;   rV   rW   rZ   rL   rX   )   rU   )r7   r6   rP   rA   r[   rU   rV   rY   rZ   rQ   rS   r;   rR   r  rW   rX   rL   rT   r[   )rL   rU   )
r7   r6   rP   rA   r[   rW   rX   rY   rU   rV   zresults*.csvzNo results.csv files found in z, nothing to plot.c                 S   s   g | ]}|  qS r   striprC  r   r   r   r      r!   z plot_results.<locals>.<listcomp>r  .)markerr   	linewidth
markersizerP   sigma:Zsmoothr   r  rL   )rF  zWARNING: Plotting error for r  r7   zresults.pngr=  r>  )rM  scipy.ndimager  r   rp  rU  rX  rY  r[  globr/   resolveread_csvr5  r   r   r  plotstem	set_titler   r   r   legendrV  rW  )rs  dirsegmentZposeZclassifyrd  pdr  rc  ZfigrH  r  filesrv  r   rf  rN   r9   r  r4  r   rg  r   r   r   plot_results  sF    



 .r  r  viridisrB  nonec                    sR   t j |d\ fddttD }tj ||||d dS )a{  
    Plots a scatter plot with points colored based on a 2D histogram.

    Args:
        v (array-like): Values for the x-axis.
        f (array-like): Values for the y-axis.
        bins (int, optional): Number of bins for the histogram. Defaults to 20.
        cmap (str, optional): Colormap for the scatter plot. Defaults to 'viridis'.
        alpha (float, optional): Alpha for the scatter plot. Defaults to 0.8.
        edgecolors (str, optional): Edge colors for the scatter plot. Defaults to 'none'.

    Examples:
        >>> v = np.random.rand(100)
        >>> f = np.random.rand(100)
        >>> plt_color_scatter(v, f)
    r9  c              
      s`   g | ]X}t tj| d dd jd d t tj | d dd jd d f qS )T)rK  r7   r   )r  r1   Zdigitizer   r=   rv  r7  vZxedgesZyedgesr   r   r      s   &&z%plt_color_scatter.<locals>.<listcomp>)r   cmapr   
edgecolorsN)r1   Zhistogram2drZ  r/   rU  Zscatter)r  rv  r:  r  r   r  r   r   r  r   plt_color_scatter  s
    
	r  tune_results.csvc                 C   s  ddl }ddlm} dd }t| } || }d}dd |jD |d }|j}|dddf }t|}	t	
t|d	 }
tjd
dd t|D ]\}}|dd|| f }||	 }t|
|
|d  t||dddd tj|| ddd tj| d|dddid tjddd ||
 dkrtg  q|| d tdt|d }tjddd tj||dddd  tj|||d!d"d#d$d%d& td' td( td) td t  || d* dS )+a  
    Plot the evolution results stored in an 'tune_results.csv' file. The function generates a scatter plot for each key
    in the CSV, color-coded based on fitness scores. The best-performing configurations are highlighted on the plots.

    Args:
        csv_file (str, optional): Path to the CSV file containing the tuning results. Defaults to 'tune_results.csv'.

    Examples:
        >>> plot_tune_results("path/to/tune_results.csv")
    r   Nr  c                 S   s*   t j| dd t   td|   dS )z#Save one matplotlib plot to 'file'.r=  r>  zSaved N)rU  rV  rW  r   rS  )rs  r   r   r   _save_one_file  s    z)plot_tune_results.<locals>._save_one_filer7   c                 S   s   g | ]}|  qS r   r  rC  r   r   r   r      r!   z%plot_tune_results.<locals>.<listcomp>r   )rY   rY   Tr@  r  rB  r  )r  r   r  zk+rS   )r  z = z.3gr   rX   )ZfontdictZbothrW   )r_  Z	labelsizeztune_scatter_plots.png)rY   rU   ofitness)r  Z	linestyler   rP   r  r  Zsmoothedr6   r  zFitness vs IterationZ	IterationZFitnessztune_fitness.png)rM  r  r  r   r  r5  r   r1   Zargmaxr  r   r/   rU  Zfigurer   Zsubplotr  r  r|   r   Ztick_paramsZyticks	with_namerZ  ZxlabelZylabelgridr  )Zcsv_filer  r  r  r   Znum_metrics_columnskeysrN   r  r  r0   r9   r   r  mur   r   r   plot_tune_results  sB    





r  ,  c           	   
   C   s   g }t | D ]d\}}|d|ddf  dd\}}}t|jd df|}|t||t	||fd qt|d
 }|dddf |dddf |ddddf |dddf fS )ZConvert model output to target format [batch_id, class_id, x, y, w, h, conf] for plotting.NrU   )rA   r7   r7   r7   r   r6   r   )r   r   r   r   r  r   appendcatr   rm  r   )	outputmax_dettargetsr9   r  r   r   ra  r  r   r   r   output_to_target  s    &"r  c           
   
   C   s   g }t | D ]Z\}}|d|  dd\}}}}t|jd df|}	|t|	||||fd qt|d }|dddf |dddf |ddddf |dddf fS )r  N)rA   r7   r7   r7   r7   r   r6   r   )	r   r   r   r   r  r   r  r  r   )
r  r  r  r9   r  r   r   ra  r"  r  r   r   r   output_to_rotated_target#  s     r      zruns/detect/expc              	   C   sL  dD ]}||v r dS qt | tjrH| j\}}}}	|dkrH|	dkrH|d| d|dd  d }
tj| d	  |d	d
}t||}tj	t
|d ddd\}}| }tjddd t|D ](}|| ||   || d qtd|
 d| d| d tj|
ddd t  tt|
d| d	    dS )a  
    Visualize feature maps of a given model module during inference.

    Args:
        x (torch.Tensor): Features to be visualized.
        module_type (str): Module type.
        stage (int): Module stage within the model.
        n (int, optional): Maximum number of feature maps to plot. Defaults to 32.
        save_dir (Path, optional): Directory to save results. Defaults to Path('runs/detect/exp').
    >   ZPoseZRTDETRDecoderZDetectZOBBZClassifySegmentNr7   stager   r  r   z_features.pngr   r   rW   T)rA  g?)ZwspaceZhspacerJ  zSaving z... (/)r  Ztight)r?  Zbbox_inchesz.npy)rz   r   r   r   r   chunkr   r  rU  rX  r  r   rY  Zsubplots_adjustrZ  r^  Zsqueezer_  r   rS  rV  rW  r1   r  r   rr  r   )rN   module_typer  r0   rc  mr   Zchannelsr  r   rv  blocksrH  r9   r   r   r   feature_visualization.  s&     
r  )r  r   FFFN)r  r  rB  r  )r  )r  )r  );r  r  rO  pathlibr   typingr   r   r   r   r   r   Zmatplotlib.pyplotZpyplotrU  r   r1   r   ZPILr   r	   r
   r   r   Zultralytics.utilsr   r   r   r   r   r   Zultralytics.utils.checksr   r   r   r   Zultralytics.utils.filesr   r   r   rI   rh  rw  Zzerosr   r3   r   Zndarrayr   r8   r  r  r  r  r  r  r  r  r  r   r   r   r   <module>   s          `6/
 &?

7

