+
    åûj5  ã                  óÌ   € R t ^ RIHt ^ RIHtHt ^ RIHtHt ^ RI	t	^ RI	H
t
 ^ RIHtHt ^ RIHt ^RIHtHtHtHtHt R	R
.t ! R R	]]
P.                  4      t ! R R
]4      tR# )uÙ  Warp images by homographies in module form, optionally reusing a precomputed sampling grid.

A warper reads ``src_homo_dst`` as the destinationâ†’source homography; :class:`HomographyWarper` takes it in
normalized :math:`[-1, 1]` coordinates by default, as :func:`~kornia.geometry.transform.homography_warp` does.

Which class to use:

- Warp ``(N, C, H, W)`` images to a fixed ``(height, width)``, optionally reusing one precomputed grid:
  :class:`HomographyWarper`.
- Write another warper for :class:`~kornia.geometry.transform.image_registrator.ImageRegistrator`: subclass
  :class:`BaseWarper`.
- For a sourceâ†’destination homography in pixel coordinates, use
  :func:`~kornia.geometry.transform.warp_perspective` instead.
)Úannotations)ÚABCÚabstractmethod)ÚAnyÚOptionalN)Únn)Ú_samples_half_in_float32Ú_torch_grid_sample)Úcreate_meshgrid)Ú_normalize_warped_pixel_gridÚ_pad_one_pixel_axesÚ_warp_pixel_gridÚhomography_warpÚ	warp_gridÚ
BaseWarperÚHomographyWarperc                  ób   a € ] tR t^1tRtR V 3R llt]R	R R ll4       t]R R l4       tRt	V ;t
# )
r   ud  Declare the interface of a homography warper module that ImageRegistrator can call.

``BaseWarper(height, width)`` only stores the destination ``height`` and ``width``. A subclass implements
``warper(patch_src, src_homo_dst)``, which samples a ``(B, C, H, W)`` source on that destination grid by a
``(B, 3, 3)`` destinationâ†’source homography, and ``precompute_warp_grid(src_homo_dst)``, which caches the grid.
:class:`~kornia.geometry.transform.image_registrator.ImageRegistrator` takes such a class as ``warper`` and calls
it as ``warper(height, width)``. Both methods are abstract: constructing ``BaseWarper`` itself, or a subclass that
does not implement both, raises ``TypeError``. To warp images, use :class:`HomographyWarper`.

Convention:
    - subclasses receive ``src_homo_dst`` as the destinationâ†’source homography

See Also:
    - :class:`HomographyWarper`: the implementation kornia ships, in normalized or pixel coordinates.
    - :class:`~kornia.geometry.transform.image_registrator.ImageRegistrator`: registers two images by
      optimizing a transform, and warps with a warper class of this interface.

c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	é   ÚheightÚintÚwidthÚargsr   ÚkwargsÚreturnÚNone© )Úformats   "ÚgC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\transform\homography_warper.pyÚ__annotate__ÚBaseWarper.__annotate__E   s/   € ÷ ñ ˜sð ¨3ð °sð Àcð Èdñ ó    c                	ó@   <€ \         SV `  ! V/ VB  Wn        W n        R # ©N)ÚsuperÚ__init__r   r   )Úselfr   r   r   r   Ú	__class__s   &&&*,€r   r%   ÚBaseWarper.__init__E   s   ø€ Ü‰Ò˜$Ð) &Ò)ØŒØŽ
r!   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   Ú	patch_srcútorch.TensorÚsrc_homo_dstúOptional[torch.Tensor]r   r   )r   s   "r   r   r    K   s#   € ÷ ñ  ð Ð=Sð Ð_kñ r!   c                ó   € R# )a9  Sample a source patch on this warper's destination grid.

Args:
    patch_src: Source image or patch tensor with shape
        ``(B, C, H, W)``, where :math:`B` is batch size,
        :math:`C` is channels, :math:`H` is source height, and
        :math:`W` is source width.
    src_homo_dst: Optional homography with shape ``(B, 3, 3)``
        mapping destination coordinates into the source image. Concrete
        implementations may also use a grid precomputed from this
        matrix.

Returns:
    Tensor sampled in the destination frame managed by this warper.
Nr   )r&   r+   r-   s   &&&r   ÚforwardÚBaseWarper.forwardJ   s   € ñ" 	r!   c               ó    € V ^8„  d   QhRRRR/# ©r   r-   r,   r   r   r   )r   s   "r   r   r    ^   s   € ÷ ñ °ð À$ñ r!   c                ó   € R# )zÉPrecompute a sampling grid for repeated homography warps.

Args:
    src_homo_dst: Homography tensor with shape ``(B, 3, 3)`` used
        to transform destination grid points into source coordinates.
Nr   )r&   r-   s   &&r   Úprecompute_warp_gridÚBaseWarper.precompute_warp_grid]   s   € ñ 	r!   )r   r   r#   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r%   r   r0   r5   Ú__static_attributes__Ú__classcell__©r'   s   @r   r   r   1   s:   ø† ñ÷&ð ð
 öó ðð$ ôó ör!   c                  óh   a € ] tR t^ht$ RtR]R&   R]R&   RR V 3R llltR R	 ltRR
 R lltRt	V ;t
# )r   u—
  Warp images to a fixed size by a normalized destinationâ†’source homography (module form).

Build ``warper = HomographyWarper(height, width)``, then ``out = warper(patch_src, src_homo_dst)`` warps
``(N, C, H, W)`` images by ``(N, 3, 3)`` destinationâ†’source homographies in normalized :math:`[-1, 1]`
coordinates and returns ``(N, C, height, width)``, as :func:`homography_warp` with ``dsize=(height, width)`` does.
To reuse one homography, call ``warper.precompute_warp_grid(src_homo_dst)`` once and then ``warper(patch_src)``; a
homography passed to the call takes precedence over the cached grid, and a call with neither raises
``RuntimeError``. For a sourceâ†’destination homography in pixel coordinates, as
:class:`~kornia.geometry.ransac.RANSAC` and :func:`~kornia.geometry.homography.find_homography_dlt` return it, use
:func:`~kornia.geometry.transform.warp_perspective`. This class has no ``normalized_homography`` switch:
``normalized_coordinates=False`` still reads a destinationâ†’source homography, in pixels.

.. math::

    X_{src} = H_{src}^{\{dst\}} * X_{dst}

Convention:
    See :doc:`Conventions & Pitfalls </get-started/conventions>` for homography direction, normalized
    coordinates and sampling conventions.

    - See the convention block of :func:`homography_warp`.
    - with ``normalized_coordinates=False`` a grid from ``precompute_warp_grid`` holds source pixel
      coordinates computed as in :func:`homography_warp` (in at least float32, unaffected by autocast), normalized
      at sampling time with the size of the patch passed to ``forward`` and then cast to the homography's dtype

Args:
    height: The height of the destination torch.Tensor.
    width: The width of the destination torch.Tensor.
    mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.
    padding_mode: padding mode for outside grid values
      ``'zeros'`` | ``'border'`` | ``'reflection'``.
    normalized_coordinates: whether the homographies are in normalized :math:`[-1, 1]` coordinates
      (``True``) or in pixel coordinates (``False``), as in :func:`homography_warp`.
    align_corners: interpolation flag.

See Also:
    - :func:`homography_warp`: the one-call form, with a ``normalized_homography`` switch for pixel
      sourceâ†’destination homographies.
    - :func:`warp_perspective`: takes the sourceâ†’destination homography in pixel coordinates.
    - :class:`BaseWarper`: the interface this class implements, for
      :class:`~kornia.geometry.transform.image_registrator.ImageRegistrator`.
    - :class:`~kornia.geometry.transform.image_registrator.ImageRegistrator`: fits a homography between two
      images, warping with this class by default.

r.   Ú_warped_gridzOptional[torch.dtype]Ú_warped_grid_dtypec               ó4   € V ^8„  d   QhRRRRRRRRRRR	RR
R/# )r   r   r   r   ÚmodeÚstrÚpadding_modeÚnormalized_coordinatesÚboolÚalign_cornersr   r   r   )r   s   "r   r   ÚHomographyWarper.__annotate__š   sP   € ÷ 'ñ 'àð'ð ð'ð ð	'ð
 ð'ð !%ð'ð ð'ð 
ñ'r!   c                	ó–   <€ \         SV `  W4       W0n        W@n        WPn        W`n        \        WWVR 7      V n        RV n        RV n	        R# ))rF   rH   N)
r$   r%   rC   rE   rF   rH   r
   Úgridr@   rA   )r&   r   r   rC   rE   rF   rH   r'   s   &&&&&&&€r   r%   ÚHomographyWarper.__init__š   sO   ø€ ô 	‰Ñ˜Ô'ØŒ	Ø(ÔØ&<Ô#Ø*Ôô $ØÐ2Hô
ˆŒ	ð
 !ˆÔØ"&ˆÖr!   c               ó    € V ^8„  d   QhRRRR/# r3   r   )r   s   "r   r   rI   ²   s   € ÷ 5ñ 5°ð 5À$ñ 5r!   c                ó8  € V P                   '       dR   \        V4      '       d   VP                  4       MTp\        V P                  V4      V n        VP                  V n        R# \        WP                  V P                  4      V n        VP                  V n        R# )aÄ  Compute and store internally the transformations of the points.

Useful when the same homography/homographies are reused.

Args:
    src_homo_dst: Homography or homographies (stacked) to
      transform all points in the grid. Shape of the homography
      has to be ``(1, 3, 3)``, ``(N, 3, 3)`` or ``(N, 1, 3, 3)``.
      The homography assumes normalized coordinates [-1, 1] if
      normalized_coordinates is True, and pixel coordinates otherwise.

N)rF   r   Úfloatr   rK   r@   ÚdtyperA   r   r   r   )r&   r-   Ú
homographys   && r   r5   Ú%HomographyWarper.precompute_warp_grid²   sv   € ð ×&×&Ð&ä1IÈ,×1WÒ1W˜×+Ñ+Ô-Ð]iˆJÜ )¨$¯)©)°ZÓ @ˆDÔØ&2×&8Ñ&8ˆDÔ#Ùô -¨\¿;¹;ÈÏ
É
ÓSˆÔØ".×"4Ñ"4ˆÖr!   c               ó$   € V ^8„  d   QhRRRRRR/# r*   r   )r   s   "r   r   rI   Ë   s(   € ÷ Mñ M ð MÐ=Sð MÐ_kñ Mr!   c           
     ó\  € V P                   pVeS   \        VVV P                  V P                  3V P                  V P
                  V P                  V P                  R7      pV# VEe¼   VP                  VP                  8X  g'   \        RVP                   RVP                   R24      h\        V RR4      p\        V4      ;'       d    WQP                  8H  pV P                  '       ga   V P                  '       d   \        WP
                  4      p\        W1P                  R	,          VP                  R
,          V P                  4      pV P                  '       * ;'       g$    V\         P"                  \         P$                  39   pVe"   V'       g   V'       d   VP'                  V4      p\)        V'       d   VP+                  4       MTV'       d   VP+                  4       MTV P                  V P
                  V P                  R7      P'                  VP                  4      pV# \-        R4      h)aO  Warp a torch.Tensor from source into reference frame.

Args:
    patch_src: The torch.Tensor to warp.
    src_homo_dst: The homography or torch.stack of
      homographies from destination to source. The homography assumes
      normalized coordinates [-1, 1] if normalized_coordinates is True,
      and pixel coordinates otherwise.

Return:
    Patch sampled at locations from source to destination.

Shape:
    - Input: ``(N, C, H, W)`` and ``(N, 3, 3)``
    - Output: ``(N, C, H, W)``

Example:
    >>> input = torch.rand(1, 3, 32, 32)
    >>> homography = torch.eye(3).view(1, 3, 3)
    >>> warper = HomographyWarper(32, 32)
    >>> # without precomputing the warp
    >>> output = warper(input, homography)  # NxCxHxW
    >>> # precomputing the warp
    >>> warper.precompute_warp_grid(homography)
    >>> output = warper(input)  # NxCxHxW

N)rC   rE   rH   rF   zDPatch and warped grid must be on the same device. Got patch.device: z warped_grid.device: zm. Whether recall precompute_warp_grid() with the correct device for the homograhy or change the patch device.rA   )rC   rE   rH   zoUnknown warping. If homographies are not provided they must be preset using the method: precompute_warp_grid().éþÿÿÿéÿÿÿÿ)r@   r   r   r   rC   rE   rH   rF   ÚdeviceÚ	TypeErrorÚgetattrr   rP   r   r   ÚshapeÚtorchÚfloat16Úbfloat16Útor	   rO   ÚRuntimeError)r&   r+   r-   r@   Úwarped_patchÚwarped_grid_dtypeÚ
in_float32Úto_homography_dtypes   &&&     r   r0   ÚHomographyWarper.forwardË   s÷  € ð8 ×(Ñ(ˆØÒ#Ü*ØØØ—‘˜dŸj™jÐ)Ø—Y‘YØ!×.Ñ.Ø"×0Ñ0Ø'+×'BÑ'BôˆLð^ ÐðM Ó%Ø×&Ñ&¨)×*:Ñ*:Ô:Üð&Ø&/×&6Ñ&6Ð%7Ð7LÈ\×M`ÑM`ÐLað b3ð3óð ô !(¨Ð.BÀDÓ IÐÜ1°)Ó<×eÐeÐAR×VeÑVeÑAeˆJØ×.×.Ð.à×%×%Ð%Ü 3°I×?PÑ?PÓ Q�IÜ;Ø §/¡/°"Õ"5°y·±ÀrÕ7JÈD×L^ÑL^ó �ð '+×&AÑ&AÔ"A÷ #ð #ÐEVÜ—‘Ü—‘ð[ñ FÐð !Ò,·Z×DWØ+Ÿ™Ð/@ÓA�Ü-ß%/�	—‘Ô!°Yß(2�×"Ñ"Ô$¸Ø—Y‘YØ!×.Ñ.Ø"×0Ñ0ô÷ ‰b�—‘Ó!ð ð Ðô ð=óð r!   )r@   rA   rH   rK   rC   rF   rE   )ÚbilinearÚzerosTFr#   )r7   r8   r9   r:   r;   Ú__annotations__r%   r5   r0   r<   r=   r>   s   @r   r   r   h   s2   ø‡ ñ,ð\ )Ó(Ø-Ó-÷'ò 'õ05÷2Mõ Mr!   )r;   Ú
__future__r   Úabcr   r   Útypingr   r   r[   r   Úkornia.core.utilsr   r	   Úkornia.geometry.gridr
   Úimgwarpr   r   r   r   r   Ú__all__ÚModuler   r   r   r!   r   Ú<module>rp      sS   ðñ$õ #ç #ß  ã Ý ç JÝ 0ç tÕ tàÐ+Ð
,€ô4��b—i‘iô 4ônp�zö pr!   