
    ^j,                     T   d dl mZmZ d dlZd dlmZmZ d dlm	Z	 d dl
mZ deddfdZ eed	d
      deddfd       ZdededdfdZ eed	d
      dededdfd       ZdededdfdZ eed	d
      dededdfd       ZdededdfdZ eed	d
      dededdfd       ZdedededdfdZ eed	d
      dedededdfd       Z eedd      dedededdfd       ZdededdfdZ eed	d
      dededdfd       Zd eeef   deddfd!Z eed	d
      d eeef   deddfd"       Zd#edededdfd$Z eed	d
      d#edededdfd%       Zd&edededdfd'Z dededededed eeef   ddfd(Z! ee!d	d
      dededededed eeef   ddfd)       Z"	 	 	 d1d#ededed*ed&ed eeeef      ddfd+Z# ee#d	d
      d#ededed eeef   ddf
d,       Z$ ee#dd      d#ededed eeef   ddf
d-       Z%d.ede&eef   fd/Z' ee'd	d
      d.ede&eef   fd0       Z(y)2    )AnyOptionalN)
deprecatedvoid)CompactMask)warn_deprecatedxyxyreturnc                     d}t        t        | dd            }t        | t        j                        xr# | j
                  dk(  xr | j                  d   dk(  }|st        d| d|       y)	zValidate that xyxy is a 2D np.ndarray with shape (N, 4).

    ```pycon
    >>> _validate_xyxy(np.array([[0, 0, 1, 1], [1, 1, 2, 2]]))

    ```
    z(_, 4)shapeN         z(xyxy must be a 2D np.ndarray with shape , but got shape strgetattr
isinstancenpndarrayndimr   
ValueError)r	   expected_shapeactual_shapeis_valids       j/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/validators/__init__.py_validate_xyxyr   
   sv     NwtWd34L$

+U		QU4::a=TUCUH6~6FFVn
 	
     z0.29.0z0.32.0)targetdeprecated_in	remove_inc                     t        |        y Nr   )r	   s    r   validate_xyxyr%      s     	Jr   masknc                    | y t        | t              r)t        |       |k7  rt        d| dt        |              y d| d}t	        t        | dd             }t        | dd       }t        | t        j                        xr, t        | j                        dk(  xr | j                  d   |k(  }|st        d	| d
| z         t        j                  |t              st        d| d       y y )Nzmask must contain z masks, but got (z, H, W)r   dtype   r   z(mask must be a 3D np.ndarray with shape r   z6A `Detections` object was created with a mask of type a@  . Masks of type other than `bool` are deprecated and may produce unexpected behavior. Starting from `supervision-0.28.0`, passing a mask with `dtype` different from `bool` to `Detections` will raise a `ValueError` during validation instead of being accepted with a warning. To migrate, please ensure your masks are boolean, for example by using `mask = np.array(..., dtype=bool)` or by converting existing masks with `mask = mask.astype(bool)` before creating the `Detections` object. If you did not create the mask manually, please report the issue to the `supervision` team.)r   r   lenr   r   r   r   r   r   
issubdtypeboolr   )r&   r'   r   r   actual_dtypeis_valid_shapes         r   _validate_maskr1   %   s   | $$t9>1!4DSYKPQQ7^NwtWd34L4$/L 	4$TTZZA)=T$**Q-STBT  6  0?@
 	
 ==t,D\N 	S# 	#	
 -r   c                     t        | |       y r#   r$   )r&   r'   s     r   validate_maskr3   K        	qMr   class_idc                     d| d}t        t        | dd             }| d u xs, t        | t        j                        xr | j
                  |fk(  }|st        d| d|       y )Nr)   ,)r   z,class_id must be a 1D np.ndarray with shape r   r   r   r   r   r   r   r   )r5   r'   r   r   r   s        r   _validate_class_idr9   T   s    2YNwx$78L4 8RZZ(CX^^t-C  :>:J K!N$
 	
 r   c                     t        | |       y r#   r$   )r5   r'   s     r   validate_class_idr;   a   s     	1r   
confidencec                     d| d}t        t        | dd            }| du xs, t        | t        j                        xr | j
                  |fk(  }|st        d| d|       y)zKValidate detection-level confidence: 1D ``np.ndarray`` with shape ``(n,)``.r)   r7   r   Nz.confidence must be a 1D np.ndarray with shape r   r8   )r<   r'   r   r   r   s        r   _validate_confidencer>   j   s    2YNwz7D9:LT! :rzz*Gz/?/?A4/G  <^<L M!N$
 	
 r   c                     t        | |       y r#   r$   )r<   r'   s     r   validate_confidencer@   x        	Qr   mc                 <   t        t        | dd            }| t        | t        j                        r| j
                  dk7  rt        d|       | j                  d   |k7  rt        d| d|       |dkD  r$| j                  d   |k7  rt        d	| d|       yyy)
zJValidate per-keypoint confidence: 2D ``np.ndarray`` with shape ``(n, m)``.r   Nr   zMkeypoint_confidence must be a 2D np.ndarray with shape (n, m), but got shape r   z,keypoint_confidence first dimension must be r   r   z-keypoint_confidence second dimension must be r   r   r   r   r   r   r   r   )r<   r'   rB   r   s       r   _validate_keypoint_confidencerE      s    wz7D9:L*bjj1Z__5I)N,  A!#>qc B!!-0  q5Z%%a(A-?s C)N,  .5 r   c                     t        | ||       y r#   r$   r<   r'   rB   s      r   validate_key_point_confidencerH           	Qr   z0.27.0z0.31.0c                     t        | ||       y r#   r$   rG   s      r   validate_keypoint_confidencerK      rI   r   
tracker_idc                     d| d}t        t        | dd             }| d u xs, t        | t        j                        xr | j
                  |fk(  }|st        d| d|       y )Nr)   r7   r   z.tracker_id must be a 1D np.ndarray with shape r   r8   )rL   r'   r   r   r   s        r   _validate_tracker_idrN      s    2YNwz7D9:LT! :rzz*Gz/?/?A4/G  <^<L M!N$
 	
 r   c                     t        | |       y r#   r$   )rL   r'   s     r   validate_tracker_idrP      rA   r   datac                    | j                         D ]  \  }}t        |t              r t        |      |k7  s%t	        d| d|       t        |t
        j                        rg|j                  dk(  r$|j                  d   |k7  rt	        d| d| d      |j                  dkD  s|j                  d   |k7  st	        d| d	|       t	        d
| d       y )NzLength of list for key 'z
' must be r   r   zShape of np.ndarray for key 'z' must be (r7   z'First dimension of np.ndarray for key 'z' must have size zValue for key 'z' must be a list or np.ndarray)	itemsr   listr,   r   r   r   r   r   )rQ   r'   keyvalues       r   _validate_datarW      s    jjl T
UeT"5zQ #;C5
1#!NOOrzz*zzQ5;;q>Q#6 #@[QRPSSU!VWWaEKKNa$7 =cUBSTUSVW  se3QRSSTr   c                     t        | |       y r#   r$   )rQ   r'   s     r   validate_datarY      r4   r   xyc           	          d| d| d| d| d	}t        t        | dd             }t        | t        j                        r | j
                  dk7  s| j                  d   dvrt        d	| d
|       y )Nr)   , z	, 2) or (z, 3)r   r+   r   )r   r+   z&xy must be a 3D np.ndarray with shape r   r   )rZ   r'   rB   r   r   s        r   _validate_xyr]      s    2aS	!Bqc6Nwr7D12Lb"**%A!F9R4^4DDTn
 	
 :Sr   c                     t        | ||       y r#   r$   )rZ   r'   rB   s      r   validate_xyr_      s     	QNr   visiblec                 <   | yt        t        | dd            }t        | t        j                        r| j
                  dk7  rt        d|       | j                  d   |k7  rt        d| d|       |dkD  r$| j                  d   |k7  rt        d	| d|       yy)
zhValidate per-keypoint visibility mask.

    Expects a 2D bool ``np.ndarray`` with shape ``(n, m)``.
    Nr   r   zAvisible must be a 2D np.ndarray with shape (n, m), but got shape r   z visible first dimension must be r   r   z!visible second dimension must be rD   )r`   r'   rB   r   s       r   _validate_visiblerb      s    
 ww67Lgrzz*glla.?%(
 	
 }}Q1.qc1A,P
 	
 	1uq!Q&/s2B<.Q
 	
 'ur   c                     t        |        t        |       }t        ||       t        ||       t	        ||       t        ||       t        ||       y r#   )r   r,   r1   r9   r>   rN   rW   )r	   r&   r5   r<   rL   rQ   r'   s          r   _validate_detections_fieldsrd     sG     4D	A4x#Q'Q'4r   c                 $    t        | |||||       y r#   r$   )r	   r&   r5   r<   rL   rQ   s         r   validate_detections_fieldsrf     s     	tXz:t<r   detection_confidencec                     t        |       }t        |       dkD  rt        | d         nd}t        | ||       t        ||       t        |||       |t	        ||       t        |||       |t        ||       y y )Nr   )r,   r]   r9   rE   r>   rb   rW   )rZ   r5   r<   rg   r`   rQ   r'   rB   s           r   _validate_keypoints_fieldsri   $  sz     	BA"gkBqE
qAQx#!*a3'115gq!$tQ r   c                      t        | |||       y r#   r$   rZ   r5   r<   rQ   s       r   validate_key_points_fieldsrl   8       	Xz4(r   c                      t        | |||       y r#   r$   rk   s       r   validate_keypoints_fieldsro   C  rm   r   
resolutionc                 F   t        | t              rt        |       dk(  st        dt	        |        d|  d      | \  }}t        |t
              rt        |t
              s$t        dt	        |       dt	        |       d      |dk  s|dk  rt        d	| d| d
      ||fS )Nr   zI
            resolution must be a tuple of two integers, got
            z with value z
            zR
            Both elements in resolution must be integers.
            Got types (r\   z)
            r   z5Both dimensions in resolution must be positive. Got (z).)r   tupler,   r   typeint)rp   whs      r   _validate_resolutionrw   N  s    z5)c*o.B*l:, 7
 	
 DAqq#:a#5Qy47) ,
 	
 	AvaCA3b2N
 	
 a4Kr   c                     t        |       S r#   r$   )rp   s    r   validate_resolutionry   e  s     
r   )NNN))typingr   r   numpyr   	deprecater   r   "supervision.detection.compact_maskr   supervision.utils.internalr   r   r%   rt   r1   r3   r9   r;   r>   r@   rE   rH   rK   rN   rP   dictr   rW   rY   r]   r_   rb   rd   rf   ri   rl   ro   rr   rw   ry    r   r   <module>r      s/      & : 6
 
 
$ 
  
#
 #
 #
 #
L 
   


 

 

 

 
   

S 
S 
T 
 
C C D 
c c c d , (
c c c d 
 (
S S S T 


S 

S 

T 

 
C C D 
Tc3h TC TD T  
S#X 3 4 

S 
S 
S 
T 
 
C C C D 

s 
s 
s 
t 
.

  	
  sCx. 
" &
=
=
= = 	=
 = sCx.= 
=
= !%%)      	 
   4S>
"  
 ( %
)))(+)37S>)	)
) %
)))(+)37S>)	)
)S U38_ . 
C E#s(O 
r   