+
    öäûjí  ã                   ó€   € ^ RI HtHtHtHtHt ^ RIt^ RIHt	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHtHt  ! R R	]4      tR# )
é    )ÚAnyÚDictÚOptionalÚTupleÚUnionN)Úrandom_generator)ÚGeometricAugmentationBase2D)ÚResample)Ú_to_device_nonblocking)Úget_perspective_transformÚwarp_perspectivec                   óº   a a€ ] tR t^t oRtR]P                  P                  RRRRR3V3R lV 3R llltV3R lR lt	RV3R	 lR
 llt
RV3R lR lltRtVtV ;t# )ÚRandomPerspectiveaK  Warp images with a random perspective transformation, applied per sample with probability ``p`` (default 0.5).

``output = RandomPerspective(distortion_scale, ...)(input)`` applies a projective warp to selected images of
shape ``(B, C, H, W)``.

Args:
    distortion_scale: the degree of distortion, ranged from 0 to 1.
    resample: the interpolation method to use.
    same_on_batch: apply the same transformation across the batch. Default: False.
    align_corners: interpolation flag.
    p: probability of applying the transformation to each sample.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
             to the batch form (False).
    sampling_method: ``'basic'`` | ``'area_preserving'``. Default: ``'basic'``
        If ``'basic'``, samples by translating the image corners randomly inwards.
        If ``'area_preserving'``, samples by randomly translating the image corners in any direction.
        Preserves area on average. See https://arxiv.org/abs/2104.03308 for further details.

Shape:
    - Input: ``(C, H, W)`` or ``(B, C, H, W)``, Optional: ``(B, 3, 3)``
    - Output: ``(B, C, H, W)``

Convention:
    - See :class:`~kornia.augmentation.GeometricAugmentationBase2D` for coordinates, defaults and inverse.
      The source corners are ``(0, 0)``, ``(W - 1, 0)``, ``(W - 1, H - 1)`` and ``(0, H - 1)``;
      ``transform_matrix`` maps them to the sampled destination corners.
    - ``basic`` samples each corner inward by at most ``distortion_scale * (W, H) / 2``. ``area_preserving``
      samples each coordinate in both directions over the same extent.
    - with ``distortion_scale=0`` and ``H > 1``, ``W > 1``, the warp is an identity up to numerical precision
      for either ``align_corners``.
    - a spatial dimension of 1 is not distorted: its source corners span a unit extent instead of ``0`` and
      its offsets are zero, so the single row or column maps onto itself and only the other axis is warped.
      At ``distortion_scale=0`` this is the identity.

.. note::
    This function internally uses :func:`kornia.geometry.transform.warp_perspective`.

.. image:: _static/img/RandomPerspective.png

See Also:
    - :class:`RandomAffine`: samples an affine rather than projective transform.
    - :class:`RandomPerspective3D`: applies a projective warp to volumes.

Examples:
    >>> rng = torch.manual_seed(0)
    >>> inputs= torch.tensor([[[[1., 0., 0.],
    ...                         [0., 1., 0.],
    ...                         [0., 0., 1.]]]])
    >>> aug = RandomPerspective(0.5, p=0.5)
    >>> out = aug(inputs)
    >>> out
    tensor([[[[0.2795, 0.3852, 0.0000],
              [0.0000, 0.6243, 0.0000],
              [0.0000, 0.0000, 0.0000]]]])
    >>> aug.inverse(out)
    tensor([[[[0.3417, 0.3022, 0.0436],
              [0.3767, 0.4769, 0.1879],
              [0.1434, 0.1958, 0.1091]]]])

To apply the exact augmenation again, you may take the advantage of the previous parameter state:
    >>> input = torch.randn(1, 3, 32, 32)
    >>> aug = RandomPerspective(0.5, p=1.)
    >>> (aug(input) == aug(input, params=aug._params)).all()
    tensor(True)

g      à?FÚbasicc                óŒ   <€ V ^8„  d   QhRS[ S[P                  S[3,          RS[ S[S[S[3,          RS[RS[RS[RS[RS[RR	/# )
é   Údistortion_scaleÚresampleÚsame_on_batchÚalign_cornersÚpÚkeepdimÚsampling_methodÚreturnN)r   ÚtorchÚTensorÚfloatÚstrÚintr
   Úbool)ÚformatÚ__classdict__s   "€ÚiC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\geometric\perspective.pyÚ__annotate__ÚRandomPerspective.__annotate__a   s   ø€ ÷ jñ já¡§¡©eÐ 3Õ4ðjñ ™™S¡(Ð*Õ+ðjñ ð	jñ
 ðjñ ðjñ ðjñ ðjð 
ñjó    c                ó    <€ \         SV `  WSVR 7       \        P                  ! WR7      V n        RVR\
        P                  ! V4      /V n        R# ))r   r   r   )r   r   r   N)ÚsuperÚ__init__ÚrgÚPerspectiveGeneratorÚ_param_generatorr
   ÚgetÚflags)	Úselfr   r   r   r   r   r   r   Ú	__class__s	   &&&&&&&&€r#   r)   ÚRandomPerspective.__init__a   sH   ø€ ô 	‰Ñ˜1À7ÐÔKÜ "× 7Ò 7Ð8HÔ jˆÔà&5°}ÀjÔRZ×R^ÒR^Ð_gÓRhÐ%iˆŽ
r&   c                óš   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[ P                  /# )r   ÚinputÚparamsr.   r   )r   r   r   r   r   )r!   r"   s   "€r#   r$   r%   p   sT   ø€ ÷ Cñ CÙ—\‘\ðCÙ+/±±U·\±\Ð0AÕ+BðCÙKOÑPSÑUXÐPXÍ>ðCá	�‰ñCr&   c                ó¸   € \        VR ,          VP                  VP                  4      p\        VR,          VP                  VP                  4      p\        WE4      # )Ústart_pointsÚ
end_points)r   ÚdeviceÚdtyper   )r/   r3   r4   r.   r6   r7   s   &&&&  r#   Úcompute_transformationÚ(RandomPerspective.compute_transformationp   sK   € ô .¨f°^Õ.DÀeÇlÁlÐTY×T_ÑT_Ó`ˆÜ+¨F°<Õ,@À%Ç,Á,ÐPU×P[ÑP[Ó\ˆ
Ü(¨ÓBÐBr&   c          
      óÄ   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[S[ P                  ,          RS[ P                  /# )r   r3   r4   r.   Ú	transformr   )r   r   r   r   r   r   )r!   r"   s   "€r#   r$   r%   w   sd   ø€ ÷ 
ñ 
á�|‰|ð
ñ ‘S™%Ÿ,™,Ð&Õ'ð
ñ ‘C™�H�~ð	
ñ
 ™EŸL™LÕ)ð
ñ 
�‰ñ
r&   c                óþ   € VP                   w   rVp\        V\        P                  4      '       g   \	        R \        V4       R24      h\        WWg3VR,          P                  P                  4       VR,          R7      # )ú0Expected the `transform` be a torch.Tensor. Got Ú.r   r   )Úmoder   )	ÚshapeÚ
isinstancer   r   Ú	TypeErrorÚtyper   ÚnameÚlower)r/   r3   r4   r.   r=   Ú_ÚheightÚwidths   &&&&&   r#   Úapply_transformÚ!RandomPerspective.apply_transformw   st   € ð $Ÿk™kÑˆˆ1�eÜ˜)¤U§\¡\×2Ò2ÜÐNÌtÐT]ËÐN_Ð_`ÐaÓbÐbäØ˜v˜o°E¸*Õ4E×4JÑ4J×4PÑ4PÓ4RÐbgÐhwÕbxô
ð 	
r&   c                óÀ   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          RS[S[ P                  ,          RS[S[S[S[3,          ,          RS[ P                  /# )r   r3   r.   r=   Úsizer   )r   r   r   r   r   r   r   r   )r!   r"   s   "€r#   r$   r%   †   sc   ø€ ÷ 
ñ 
á�|‰|ð
ñ ‘C™�H�~ð
ñ ™EŸL™LÕ)ð	
ñ
 ‘u™S¡#˜X•Õ'ð
ñ 
�‰ñ
r&   c           
     ó  € \        V\        P                  4      '       g   \        R \	        V4       R24      hV P                  VV P                  \        P                  ! W1P                  VP                  R7      VR7      # )r?   r@   )r8   r9   )r4   r=   r.   )
rC   r   r   rD   rE   rK   Ú_paramsÚ	as_tensorr8   r9   )r/   r3   r.   r=   rN   s   &&&&&r#   Úinverse_transformÚ#RandomPerspective.inverse_transform†   sl   € ô ˜)¤U§\¡\×2Ò2ÜÐNÌtÐT]ËÐN_Ð_`ÐaÓbÐbØ×#Ñ#ØØ—<‘<Ü—o’o i¿¹ÈEÏKÉKÔXØð	 $ó 
ð 	
r&   )r,   r.   )N)NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r
   ÚBILINEARrF   r)   r:   rK   rR   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r0   r"   s   @@r#   r   r      s`   ù‡ € ñAðJ 8;Ø.6×.?Ñ.?×.DÑ.DØ#Ø#ØØØ&÷jõ j÷Cð C÷
ò 
÷
÷ 
ò 
r&   r   )Útypingr   r   r   r   r   r   Úkornia.augmentationr   r*   Ú&kornia.augmentation._2d.geometric.baser	   Úkornia.constantsr
   Úkornia.core.utilsr   Úkornia.geometry.transformr   r   r   © r&   r#   Ú<module>rd      s.   ð÷$ 5Õ 4ã å 6Ý NÝ %Ý 4ß Qôw
Ð3ö w
r&   