
    3j/                         S SK JrJrJrJrJr  S SKrS SKJr  S SKJ	r	  SS/r
S\\R                  R                     S\R                  R                  4S	 jr " S
 S5      r " S S\5      r " S S5      rg)    )ListOptionalTupleUnioncastN)Size)transform_points	KeypointsKeypoints3D	keypointsreturnc                     [         eNNotImplementedError)r   s    S/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/geometry/keypoints.py_merge_keypoint_listr      s    
    c            	       ~   \ rS rSrSr S"S\\R                  R                  \\R                  R                     4   S\	SS4S jjr
S\\\\R                  R                  4   SS 4S	 jrS\\\\R                  R                  4   S
S SS 4S jr\S\\\S4   \4   4S j5       r\S\R                  R                  4S j5       r\S\R(                  4S j5       r\S\R*                  4S j5       r S#S\\\R                  R                  S4   \\R                  R                     4   S\\R                  R                  S 4   S\	SS 4S jjrS\R                  R                  SS 4S jrS\R                  R                  SS 4S jrS#S\R                  R                  S\	SS 4S jjrS\R                  R                  SS 4S jr\S\R                  R                  SS 4S j5       rS#S\	S\\R                  R                  \\R                  R                     4   4S jjrS$S jrS\R*                  SS 4S  jrS!r g)%r
       z2D Keypoints containing Nx2 or BxNx2 points.

Args:
    keypoints: Raw tensor or a list of torch.Tensors with the Nx2 coordinates
    raise_if_not_floating_point: will raise if the torch.Tensor isn't float

r   raise_if_not_floating_pointr   Nc                    S U l         [        U[        5      (       a  [        U5      u  ol         [        U[        R                  R
                  5      (       d  [        S[        U5       S35      eUR                  5       (       d/  U(       a  [        SUR                   35      eUR                  5       n[        UR                  5      S:X  a  UR                  S5      nSUR                  s=::  a  S::  a  O  OUR                  SS  S	:X  d  [        S
UR                   S35      eUR                  S:X  a  SOSU l        Xl        g )N,Input keypoints is not a torch.Tensor. Got: .+Coordinates must be in floating point. Got r   )   r      r   )r   z1Keypoints shape must be (N, 2) or (B, N, 2). Got FT_N
isinstancelistr   torchTensor	TypeErrortypeis_floating_point
ValueErrordtypefloatlenshapereshapendim_is_batched_dataselfr   r   s      r   __init__Keypoints.__init__)       (,i&&!5i!@Iw)U[[%7%788J4PY?J[[\]^^**,,* #NyN_!`aa!)Iy1$ "))'2IY^^(q(Y__RS-AT-IPQZQ`Q`Paabcdd$-NNa$75T
r   keyc                 D    [        U 5      " U R                  U   S5      nU$ NFr&   r0   r2   r6   new_objs      r   __getitem__Keypoints.__getitem__F       t*TZZ_e4r   valuec                 8    UR                   U R                   U'   U $ r   r0   r2   r6   r?   s      r   __setitem__Keypoints.__setitem__J       ++

3r   .c                 .    U R                   R                  $ r   datar,   r2   s    r   r,   Keypoints.shapeN       yyr   c                     U R                   $ r   rA   rI   s    r   rH   Keypoints.dataR       zzr   c                 .    U R                   R                  $ )zReturns keypoints device.)r0   devicerI   s    r   rP   Keypoints.deviceV   s     zz   r   c                 .    U R                   R                  $ )zReturns keypoints dtype.)r0   r)   rI   s    r   r)   Keypoints.dtype[   s     zzr   indicesvaluesinplacec                 $   U(       a  U R                   nOU R                   R                  5       n[        U[        5      (       a  UR	                  XR
                  5        OUR	                  X5        U(       a  U $ U R                  5       nXEl         U$ r   )r0   cloner!   r
   
index_put_rH   )r2   rT   rU   rV   r0   objs         r   	index_putKeypoints.index_put`   sl     JJEJJ$$&Efi((Wkk2W-Kjjl	
r   padding_sizec                    [        UR                  5      S:X  a  UR                  S5      S:X  d  [        SUR                   S35      eU R                  S==   USSS24   -  ss'   U R                  S	==   USSS
24   -  ss'   U $ z;Pad a bounding keypoints.

Args:
    padding_size: (B, 4)

r         z%Expected padding_size as (B, 4). Got r   ).r   .N).r`   r   r+   r,   sizeRuntimeErrorr0   r2   r]   s     r   padKeypoints.padw        L&&'1,1B1B11E1J!F|GYGYFZZ[\]]

6l3733

6l3!844r   c                    [        UR                  5      S:X  a  UR                  S5      S:X  d  [        SUR                   S35      eU R                  S==   USSS24   -  ss'   U R                  S	==   USSS
24   -  ss'   U $ r_   rb   re   s     r   unpadKeypoints.unpad   rh   r   Mc                     SUR                   s=::  a  S::  a  O  OUR                  SS S:w  a  [        SUR                   S35      e[        XR                  5      nU(       a  X0l        U $ [        US5      $ )	Apply a transformation matrix to the 2D keypoints.

Args:
    M: The transformation matrix to be applied, shape of :math:`(3, 3)` or :math:`(B, 3, 3)`.
    inplace: do transform in-place and return self.

Returns:
    The transformed keypoints.

r   r   N)r   r   zAThe transformation matrix shape must be (3, 3) or (B, 3, 3). Got r   F)r.   r,   r(   r	   r0   r
   )r2   rl   rV   transformed_boxess       r   transform_keypointsKeypoints.transform_keypoints   sn     AFFa17723<6#9`abahah`iijkll,Q

;*JK*E22r   c                 "    U R                  USS9$ z9Inplace version of :func:`Keypoints.transform_keypoints`.TrV   rq   r2   rl   s     r   transform_keypoints_Keypoints.transform_keypoints_       ''4'88r   c                     U " U5      $ r    clsr   s     r   from_tensorKeypoints.from_tensor       9~r   as_padded_sequencec                 4    U(       a  [         eU R                  $ )aY  Cast :class:`Keypoints` to a tensor.

``mode`` controls which 2D keypoints format should be use to represent keypoints in the tensor.

Args:
    as_padded_sequence: whether to keep the pads for a list of keypoints. This parameter is only valid
        if the keypoints are from a keypoint list.

Returns:
    Keypoints tensor :math:`(B, N, 2)`

r   r0   r2   r   s     r   	to_tensorKeypoints.to_tensor        %%zzr   c                 J    [        U R                  R                  5       S5      $ r8   )r
   r0   rX   rI   s    r   rX   Keypoints.clone   s    ))+U33r   r)   c                 F    U R                   R                  U5      U l         U $ r   )r0   r&   )r2   r)   s     r   r&   Keypoints.type   s    ZZ__U+
r   r    r0   r/   TF)r   r
   )!__name__
__module____qualname____firstlineno____doc__r   r#   r$   r   boolr3   sliceintr<   rC   propertyr   r   r,   rH   rP   r)   r[   rf   rj   rq   rx   classmethodr   r   rX   r&   __static_attributes__r|   r   r   r
   r
       s    swu{{1148J8J3KKLko	:uUC1C1C%CD  uUC1C1C%CD [ ]h  uU38_d23   ekk((   ! ! !  u{{     	uU[[//45tEKK<N<N7OOP ekk((+56 	
 
. 2 2 { %++"4"4  3U[[%7%7 3$ 3S^ 3*9ekk&8&8 9[ 9 EKK$6$6 ;  D U5;;CUCUW[\a\g\g\n\nWoCo=p "4%++ + r   c                   <  ^  \ rS rSr% \\S'   \ SS\\R                  R                  \
\R                  R                     4   S\SS 4S jj5       rS\R                  R                  4U 4S jjrSS\R                  R                  S	\SS 4U 4S
 jjjrSS jrSrU =r$ )VideoKeypoints   temporal_channel_sizeboxesvalidate_boxesr   c           	      V   [        U[        45      (       d'  UR                  5       S:w  d  UR                  S   S:w  a  [	        S5      eUR                  S5      nU " UR                  UR                  S5      UR                  S5      -  SUR                  S5      5      5      nX4l        U$ )Nra   r   r   zOInput box type is not yet supported. Please input an `BxTxNx2` tensor directly.r`   r   r   )r!   r"   dimr,   r(   rc   viewr   )r~   r   r   r   outs        r   r   VideoKeypoints.from_tensor   s     edW%%%))+*:ekk"oQR>Rnoo %

1 %**UZZ]UZZ]:B

1NO$9!
r   c                    > [         TU ]  SS9n[        [        R                  R                  U5      nUR
                  " SU R                  /UR                  SS  Q76 $ )NF)r   r   r`   )superr   r   r#   r$   r   r   r,   )r2   r   	__class__s     r   r   VideoKeypoints.to_tensor   sQ    g595;;%%s+xxD66G12GGr   rl   rV   c                    > [         TU ]  XS9nU(       a  U $ [        UR                  S5      nU R                  Ul        U$ )Nru   F)r   rq   r   rH   r   )r2   rl   rV   r   r   s       r   rq   "VideoKeypoints.transform_keypoints   s@    g)!)=KSXXu-$($>$>!
r   c                 p    [        U R                  R                  5       S5      nU R                  Ul        U$ r8   )r   r0   rX   r   )r2   r   s     r   rX   VideoKeypoints.clone   s.    TZZ--/7$($>$>!
r   r|   r   r   )r   r   )r   r   r   r   r   __annotations__r   r   r#   r$   r   r   r   r   rq   rX   r   __classcell__)r   s   @r   r   r      s    `d%++,,d5;;3E3E.FFGY]	 H5;;-- H
U[[%7%7 $ Sc   r   r   c                      \ rS rSrSr SS\\R                  R                  \\R                  R                     4   S\	SS4S jjr
S\\\\R                  4   SS 4S	 jrS\\\\R                  4   S
S SS 4S jr\S\4S j5       r\S\R                  R                  4S j5       rS\R                  R                  SS 4S jrS\R                  R                  SS 4S jrSS\R                  S\	SS 4S jjrS\R                  SS 4S jr\S\R                  SS 4S j5       rSS\	S\\R                  R                  \\R                  R                     4   4S jjrSS jrSrg)r      z3D Keypoints containing Nx3 or BxNx3 points.

Args:
    keypoints: Raw tensor or a list of torch.Tensors with the Nx3 coordinates
    raise_if_not_floating_point: will raise if the torch.Tensor isn't float

r   r   r   Nc                    S U l         [        U[        5      (       a  [        U5      u  ol         [        U[        R                  R
                  5      (       d  [        S[        U5       S35      eUR                  5       (       d/  U(       a  [        SUR                   35      eUR                  5       n[        UR                  5      S:X  a  UR                  S5      nSUR                  s=::  a  S::  a  O  OUR                  SS  S	:X  d  [        S
UR                   S35      eUR                  S:X  a  SOSU l        Xl        g )Nr   r   r   r   )r   r   r   r   r   )r   z1Keypoints shape must be (N, 3) or (B, N, 3). Got FTr   r1   s      r   r3   Keypoints3D.__init__   r5   r   r6   c                 D    [        U 5      " U R                  U   S5      nU$ r8   r9   r:   s      r   r<   Keypoints3D.__getitem__  r>   r   r?   c                 8    UR                   U R                   U'   U $ r   rA   rB   s      r   rC   Keypoints3D.__setitem__  rE   r   c                 .    U R                   R                  $ r   rG   rI   s    r   r,   Keypoints3D.shape  rK   r   c                     U R                   $ r   rA   rI   s    r   rH   Keypoints3D.data  rN   r   r]   c                     [         ez;Pad a bounding keypoints.

Args:
    padding_size: (B, 6)

r   re   s     r   rf   Keypoints3D.pad"  
     "!r   c                     [         er   r   re   s     r   rj   Keypoints3D.unpad+  r   r   rl   rV   c                     [         e)rn   r   )r2   rl   rV   s      r   rq   Keypoints3D.transform_keypoints4  s
     "!r   c                 "    U R                  USS9$ rt   rv   rw   s     r   rx    Keypoints3D.transform_keypoints_A  rz   r   c                     U " U5      $ r   r|   r}   s     r   r   Keypoints3D.from_tensorE  r   r   r   c                 4    U(       a  [         eU R                  $ )aY  Cast :class:`Keypoints` to a tensor.

``mode`` controls which 2D keypoints format should be use to represent keypoints in the tensor.

Args:
    as_padded_sequence: whether to keep the pads for a list of keypoints. This parameter is only valid
        if the keypoints are from a keypoint list.

Returns:
    Keypoints tensor :math:`(B, N, 3)`

r   r   s     r   r   Keypoints3D.to_tensorI  r   r   c                 J    [        U R                  R                  5       S5      $ r8   )r   r0   rX   rI   s    r   rX   Keypoints3D.cloneZ  s    4::++-u55r   r   r   r   )r   r   )r   r   r   r   r   r   r#   r$   r   r   r3   r   r   r<   rC   r   r   r,   rH   rf   rj   rq   rx   r   r   r   rX   r   r|   r   r   r   r      s    swu{{1148J8J3KKLko	:uUC%=> = uUC%=> } Yf  t   ekk((  " 2 2 "} ""%++"4"4 " ""U\\ "D "] "9ell 9} 9 ELL ]  D U5;;CUCUW[\a\g\g\n\nWoCo=p "6r   )typingr   r   r   r   r   r#   r   kornia.geometryr	   __all__r$   r   r
   r   r   r|   r   r   <module>r      sr   $ 6 5   ,
&D););$< ASAS d dN"Y "Jo6 o6r   