o
    e                     @   s   d dl mZ d dlmZmZ d dlZd dlmZ d dl	m
Z
mZ d dlmZ G dd deZejfd	ed
edeeejf defddZdee
ef dede
fddZejfdee
ef d	ed
edeeejf de
f
ddZG dd dZdS )    )Enum)OptionalUnionN)
Detections)ColorColorPalette)Positionc                   @   s(   e Zd ZdZdZdZdZedd ZdS )ColorLookupa  
    Enumeration class to define strategies for mapping colors to annotations.

    This enum supports three different lookup strategies:
        - `INDEX`: Colors are determined by the index of the detection within the scene.
        - `CLASS`: Colors are determined by the class label of the detected object.
        - `TRACK`: Colors are determined by the tracking identifier of the object.
    indexclasstrackc                 C   s   t tdd | S )Nc                 S   s   | j S N)value)c r   K/var/www/myenv/lib/python3.10/site-packages/supervision/annotators/utils.py<lambda>   s    z"ColorLookup.list.<locals>.<lambda>)listmap)clsr   r   r   r      s   zColorLookup.listN)	__name__
__module____qualname____doc__INDEXCLASSTRACKclassmethodr   r   r   r   r   r	      s    	r	   
detectionsdetection_idxcolor_lookupreturnc                 C   s   |t | krtd| dt |  t|tjr2t |t | kr.tdt | dt |  || S |tjkr9|S |tjkrL| jd u rGtd| j| S |tj	kr_| j
d u rZtd| j
| S d S )NzDetection index z*is out of bounds for detections of length zLength of color lookup z$does not match length of detections zGCould not resolve color by class becauseDetections do not have class_idzICould not resolve color by track becauseDetections do not have tracker_id)len
ValueError
isinstancenpndarrayr	   r   r   class_idr   
tracker_idr   r   r    r   r   r   resolve_color_idx   s:   






r*   coloridxc                 C   s   t | tr
| |S | S r   )r$   r   by_idxr+   r,   r   r   r   get_color_by_indexB   s   

r/   c                 C   s   t |||d}t| |dS )Nr)   r.   )r*   r/   )r+   r   r   r    r,   r   r   r   resolve_colorH   s   r0   c                	   @   sZ   e Zd Zddejfdee dededdfddZd	eddfd
dZ	dede
jfddZdS )TraceNr   max_sizestart_frame_idanchorr!   c                 C   sH   || _ || _|| _tjg td| _tjdtjd| _	tjg td| _
d S )Ndtype)r      )current_frame_idr2   r4   r%   arrayintframe_idemptyfloat32xyr(   )selfr2   r3   r4   r   r   r   __init__W   s   zTrace.__init__r   c                 C   s   t jt|| jtd}t | j|g| _t | j|| j	g| _t | j
|j
g| _
t | j}d| j  k r>t|k r_n n| j| j d }| j|k}| j| | _| j| | _| j
| | _
|  jd7  _d S )Nr5   r      )r%   fullr"   r8   r:   concatenater;   r>   get_anchors_coordinatesr4   r(   uniquer2   )r?   r   r;   unique_frame_idmax_allowed_frame_idfiltering_maskr   r   r   pute   s   
z	Trace.putr(   c                 C   s   | j | j|k S r   )r>   r(   )r?   r(   r   r   r   getx   s   z	Trace.get)r   r   r   r   CENTERr   r:   r@   r   rI   r%   r&   rJ   r   r   r   r   r1   V   s    
r1   )enumr   typingr   r   numpyr%   supervision.detection.corer   supervision.draw.colorr   r   supervision.geometry.corer   r	   r   r:   r&   r*   r/   r0   r1   r   r   r   r   <module>   s>    
$


