+
    åûj» ã                   óX  € R t ^ RIt^ RIt^ RIHtHtHt ^ RIt^ RIH	t	H
t
 ^ RIHt ^ RIHtHtHtHtHtHtHt ^ RIHtHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IH t H!t!H"t" ^ RI#H$t$ . R<Ot%]]PL                  ]PL                  3,          t'R=R R llt(R=R R llt)R>R R llt*R?R R llt+R R lt,R R lt-R R lt.R R lt/R R lt0R R lt1R  R! lt2R" R# lt3R$ R% lt4R& R' lt5R@R( R) llt6R* R+ lt7RAR, R- llt8R. R/ lt9R0 R1 lt:R2 R3 lt;RBR4 R5 llt<R6 R7 lt=RAR8 R9 llt>RCR: R; llt?R# )DaF  Estimate homographies from point or line-segment correspondences, and score them.

A homography ``H`` ``(B, 3, 3)`` maps the first image to the second, :math:`x_2 \sim H x_1` for homogeneous
points, as ``cv2.findHomography(src, dst)`` does: the source-to-destination pixel homography that
:func:`~kornia.geometry.transform.warp_perspective` takes. Correspondences are ``(B, N, 2)`` points, or
``(B, N, 2, 2)`` segments as ``[start, end]`` pairs of ``(x, y)`` points, with the first image's argument first. The
estimators scale ``H`` to ``H[2, 2] = 1``, unless that entry is numerically zero. The errors do not depend on the
scale of ``H`` and are distances in the units of the points: squared by default for points, unsquared for segments.
:ref:`Two-view geometry <two-view-conventions>` compares these conventions with OpenCV's.

Which function to use:

- A homography from correspondences known to be inliers: :func:`find_homography_dlt` from four or more points,
  optionally weighted, and :func:`find_homography_lines_dlt` from four or more line segments.
  :func:`find_homography_dlt_iterated` and :func:`find_homography_lines_dlt_iterated` re-weight them by their
  residuals over a few iterations. Exactly four points in closed form:
  :func:`~kornia.geometry.transform.get_perspective_transform`. With outliers:
  :class:`~kornia.geometry.ransac.RANSAC`.
- How well correspondences fit a homography: :func:`oneway_transfer_error` measures in image 2 only,
  :func:`symmetric_transfer_error` in both images through ``H`` and its inverse, and
  :func:`sampson_homography_distance` is the first-order error of moving both points.
  :func:`line_segment_transfer_error_one_way` scores segments by the distance of their mapped endpoints from the
  matched line.
- Whether four correspondences keep their orientation, as two views of a plane in front of both cameras do, before
  fitting them: :func:`sample_is_valid_for_homography`. A mirroring homography fails this test.
- A two-view model other than a plane: :func:`~kornia.geometry.epipolar.find_fundamental`,
  :func:`~kornia.geometry.epipolar.find_essential`.
N)ÚOptionalÚTupleÚUnion)ÚKORNIA_CHECKÚKORNIA_CHECK_SHAPE)Ú
ShapeError)Ú_at_least_float32Ú_autocast_disabledÚ_extract_device_dtypeÚ_symmetric_eigenvectorÚ_torch_svd_in_work_dtypeÚsafe_inverse_with_maskÚsafe_solve_with_mask)Úconvert_points_from_homogeneousÚconvert_points_to_homogeneous)Únormalize_pointsÚnormalize_transformation)Ú_shares_points)Ú_robust_loss)Ú
_inf_whereÚ_nonzeroÚ_sqrt_or_zero)Ú_null_space_luc                ó°   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\         P                  /# ©é   Úpts1Úpts2ÚHÚsquaredÚepsÚreturn©ÚtorchÚTensorÚboolÚfloat)Úformats   "ÚVC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\homography.pyÚ__annotate__r)   V   sT   € ÷ Z4ñ Z4Ü
�,‰,ðZ4Ü#Ÿl™lðZ4Ü/4¯|©|ðZ4ÜFJðZ4ÜX]ðZ4ä
‡\�\ñZ4ó    c                ó\  € \        V. RO4       VP                  ^ ,          ^8¼  d   \        W4      '       d   \        WW#4      # V P                  R,          ^8X  d   \	        V 4      pVR,          pVR,          pMV R,          pV R,          pVP                  R,          ^8X  d   \	        V4      pVR,          p	VR,          p
MVR,          p	VR,          p
VR,          R,          pVR	,          R,          pVR
,          R,          pVR,          R,          pVR,          R,          pVR,          R,          pVR,          R,          pVR,          R,          pVR,          R,          pW¶,          WÇ,          ,           V,           pWæ,          W÷,          ,           V,           pVV,          VV,          ,           V,           p\        V4      pVV,          pVV,          p\        VV	,
          P                  ^4      VV
,
          P                  ^4      ,           V^ 8H  4      pV'       d   V# \        V4      # )a7
  Compute the squared transfer error in image 2 of correspondences under a homography.

``err = oneway_transfer_error(pts1, pts2, H)`` takes correspondences ``(B, N, 2)``, or homogeneous
``(B, N, 3)``, and homographies ``(B, 3, 3)`` that map the first image to the second, and returns, per
correspondence, ``(B, N)`` with the batch dimensions broadcast, the squared distance in image 2 between ``H``
applied to ``pts1`` and ``pts2``, in the squared units of the points; ``squared=False`` returns the distance. It
is the residual :class:`~kornia.geometry.ransac.RANSAC` scores homographies with. It measures in image 2 only:
for both images, use :func:`symmetric_transfer_error`, and for the first-order error of moving both points,
:func:`sampson_homography_distance`.

Convention:
    - One set of correspondences scored against several homographies (points with leading dimensions of
      size 1) is computed from one matrix product for all of them, in at least float32; the result matches the
      per-homography computation to roundoff.
    - ``squared=True``, the default here and in :func:`symmetric_transfer_error`, returns the squared
      distance; :func:`line_segment_transfer_error_one_way` defaults to ``squared=False``.
    - The error does not depend on the scale of ``H``, and an exact match scores exactly 0, with a zero
      gradient, with ``squared=False``. A point that ``H`` maps to infinity (:math:`w' = 0`) has error ``inf``.

Args:
    pts1: correspondences from the left images with shape
      ``(B, N, 2)`` or ``(B, N, 3)``. If they are homogeneous, converted automatically.
    pts2: correspondences from the right images with shape
      ``(B, N, 2)`` or ``(B, N, 3)``. If they are homogeneous, converted automatically.
    H: Homographies with shape ``(B, 3, 3)``.
    squared: if True (default), the squared distance is returned.
    eps: unused; it was added to the projective denominator and inside the square root, which made the error
        depend on the scale of ``H`` and an exact match score ``sqrt(eps)`` (#4881). The singular case is
        guarded exactly instead. Accepted so that existing calls keep working.

Returns:
    the computed distance with shape ``(B, N)``.

See Also:
    - :func:`symmetric_transfer_error`: the image-1 error of the inverse homography added.
    - :func:`sampson_homography_distance`: the first-order error of moving both points.
    - :func:`line_segment_transfer_error_one_way`: the image-2 error of line segments.
    - :func:`~kornia.geometry.epipolar.left_to_right_epipolar_distance`: the image-2 error of a fundamental
      matrix.

©ÚBÚ3r.   éÿÿÿÿ©.é    ©.é   ).ºNNNr1   ).r4   r3   ©.r1   r1   ©.N).r1   r3   ).r1   r   ).r3   r1   ).r3   r3   ).r3   r   ).r   r1   ).r   r3   ).r   r   )	r   Úshaper   Ú#_oneway_transfer_error_shared_impl_r   r   r   Úpowr   )r   r   r   r   r    Úx1y1Úx1Úy1Úu2v2Úu2Úv2Úh00Úh01Úh02Úh10Úh11Úh12Úh20Úh21Úh22Úx_numÚy_numÚw_denÚw_safeÚu1in2Úv1in2Úerr2s   &&&&&                      r(   Úoneway_transfer_errorrP   V   sÔ  € ôX �qš/Ô*Ø‡w�wˆq…z�Q„œ>¨$×5Ò5Ü2°4¸qÓJÐJà‡z�z�"…~˜ÔÜ.¨tÓ4ˆØ�&�\ˆØ�&�\‰à�)�_ˆØ�)�_ˆà‡z�z�"…~˜ÔÜ.¨tÓ4ˆØ�&�\ˆØ�&�\‰à�)�_ˆØ�)�_ˆð ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€CØ
ˆI�,�yÕ
!€Cð �H�s•xÕ #Õ%€EØ�H�s•xÕ #Õ%€EØ�"�H�s˜R•xÕ #Õ%€Eô �e‹_€FØ�F�N€EØ�F�N€Eô �u˜r•z×&Ñ& qÓ)¨U°R­Z×,<Ñ,<¸QÓ,?Õ?ÀÈ!ÁÓL€Dßˆ4Ð3¤¨dÓ 3Ð3r*   c                ó°   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\         P                  /# r   r"   )r'   s   "r(   r)   r)   ³   sL   € ÷ ?8ñ ?8Ü
�,‰,ð?8Ü#Ÿl™lð?8Ü/4¯|©|ð?8ÜFJð?8ÜX]ð?8ä
‡\�\ñ?8r*   c                ó  € \        V. RO4       V P                  R4      ^8X  d   \        V 4      p VP                  R4      ^8X  d   \        V4      p\        P                  ! V P
                  4      P                  p\        VP                  4       4      w  rg\        P                  ! ^VP                  VP
                  R7      P                  V4      p\        P                  ! VP                  R^^4      W(4      p	\        V	4      w  r¦\        WV	R4      p\        WV
R4      pVP                  R^4      P                  V4      pW¼,           pV'       g   \        V4      p\        P                   ! Wå4      p\        P                  ! WÞV4      # )a-  Compute the symmetric transfer error of correspondences under a homography, in both images.

``err = symmetric_transfer_error(pts1, pts2, H)`` takes the arguments of :func:`oneway_transfer_error` and
returns, per correspondence, ``(B, N)``, the squared image-2 transfer error of ``H`` plus the squared image-1
transfer error of :math:`H^{-1}`; ``squared=False`` returns the square root of that sum. A homography that is not
invertible scores the largest finite value of the dtype. :func:`find_homography_dlt_iterated` re-weights its
correspondences by it. For the first-order error of moving both points, use :func:`sampson_homography_distance`.

Convention:
    - Argument order as :func:`oneway_transfer_error`.
    - As :func:`oneway_transfer_error`, the error does not depend on the scale of ``H`` and an exact match
      scores exactly 0 with ``squared=False``.

Args:
    pts1: correspondences from the left images with shape
      ``(B, N, 2)`` or ``(B, N, 3)``. If they are homogeneous, converted automatically.
    pts2: correspondences from the right images with shape
      ``(B, N, 2)`` or ``(B, N, 3)``. If they are homogeneous, converted automatically.
    H: Homographies with shape ``(B, 3, 3)``.
    squared: if True (default), the squared distance is returned.
    eps: unused, as in :func:`oneway_transfer_error` (#4881).

Returns:
    the computed distance with shape ``(B, N)``. Rows whose homography is not invertible
    score ``max_num``, i.e. ``torch.finfo(pts1.dtype).max``, for both values of ``squared``.

See Also:
    - :func:`oneway_transfer_error`: the image-2 term alone.
    - :func:`sampson_homography_distance`: the first-order error of moving both points, without an inverse.
    - :func:`~kornia.geometry.epipolar.symmetrical_epipolar_distance`: the two-image error of a fundamental
      matrix.

©ÚdeviceÚdtypeTr,   r/   )r   Úsizer   r#   ÚfinforU   Úmaxr   ÚdetachÚeyerT   Ú	expand_asÚwhereÚviewrP   r   Ú	full_like)r   r   r   r   r    Úmax_numÚ_Úgood_HrZ   ÚH_safeÚ
H_inv_safeÚthereÚbackÚgood_H_reshapeÚoutÚ
max_tensors   &&&&&           r(   Úsymmetric_transfer_errorri   ³   s'  € ôH �qš/Ô*Ø‡y�y�ƒ}˜ÔÜ.¨tÓ4ˆà‡y�y�ƒ}˜ÔÜ.¨tÓ4ˆä�kŠk˜$Ÿ*™*Ó%×)Ñ)€Gô ' q§x¡x£zÓ2�I€AÜ
�)Š)�A˜aŸh™h¨a¯g©gÔ
6×
@Ñ
@ÀÓ
C€CÜ�[Š[˜Ÿ™ R¨¨AÓ.°Ó7€FÜ*¨6Ó2�M€Jä/°¸FÀDÓI€EÜ.¨t¸:ÀtÓL€DØ#)§;¡;¨r°1Ó#5×#?Ñ#?ÀÓ#F€Nà
�,€CßÜ˜CÓ ˆÜ—’ Ó.€JÜ�;Š;�~¨JÓ7Ð7r*   c          
      ó¤   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\         P                  /# ©r   r   r   r   r   r!   ©r#   r$   r%   )r'   s   "r(   r)   r)   õ   sK   € ÷ Xñ XÜ
�,‰,ðXÜ#Ÿl™lðXÜ/4¯|©|ðXÜFJðXä
‡\�\ñXr*   c           
     ó  € \        V. RO4       \        V P                  R,          R9   ;'       d    VP                  R,          R9   R4       \        P                  ! \        P                  ! V P
                  VP
                  4      VP
                  4      p\        P                  ! V\        P                  4      pVP                  '       d   TMTpV P                  V4      VP                  V4      rV P                  R,          ^8X  dM   \        P                  ! V 4      P                  RRR7      p\        V 4      P                  V( \        R4      4      p VP                  R,          ^8X  dM   \        P                  ! V4      P                  RRR7      p\        V4      P                  V( \        R4      4      pV R	,          V R
,          r˜VR	,          VR
,          rºVP                  V4      pVP                  4       P                  RRR7      pV\        P                   ! V^ 8„  V\        P"                  ! V4      4      ,          R,          pVR,          V,          VR,          V	,          ,           VR,          ,           pVR,          V,          VR,          V	,          ,           VR,          ,           pVR,          V,          VR,          V	,          ,           VR,          ,           pVV,          V,
          WêV,          ,
          ppW½R,          ,          VR,          ,
          W½R,          ,          VR,          ,
          ppVR,          W­R,          ,          ,
          VR,          W­R,          ,          ,
          ppVP%                  4       VP%                  4       ,           VP%                  4       ,           pVP%                  4       VP%                  4       ,           VP%                  4       ,           pVV,          VV,          ,           pVV,          VP%                  4       ,
          pVVP%                  4       ,          ^V,          V,          V,          ,
          VVP%                  4       ,          ,           pV\        P                   ! V^ 8„  V\        P"                  ! V4      4      ,          p\        P                   ! V^ 8*  \        P&                  ! V\(        P*                  4      V4      p\        P                   ! V^ 8  \        P,                  ! V4      V4      pV'       gV   V^ 8„  p\        P                   ! V\        P                   ! VV\        P"                  ! V4      4      P/                  4       V4      pVP                  V4      # )aG
  Compute the Sampson distance of correspondences to a homography, to first order.

``d = sampson_homography_distance(pts1, pts2, H)`` takes correspondences ``(B, N, 2)``, or homogeneous
``(B, N, 3)``, and homographies ``(B, 3, 3)`` that map ``pts1`` to ``pts2``, and returns, per correspondence,
``(B, N)``, the squared Sampson distance; ``squared=False`` returns its square root. Unlike
:func:`oneway_transfer_error` and :func:`symmetric_transfer_error`, it accounts for the noise of both points in
one term and needs no inverse homography. For a fundamental matrix, use
:func:`~kornia.geometry.epipolar.sampson_epipolar_distance`.

The first-order approximation of the geometric error: the squared distance by which ``pts1`` and ``pts2``
together must move for :math:`x_2 \sim H x_1` to hold (Hartley and Zisserman, *Multiple View Geometry*, 2nd ed.,
section 4.2.6). With :math:`x_1 = (x, y, 1)`, :math:`x_2 = (u, v, 1)` and :math:`H x_1 = (p, q, w)`, the
algebraic residuals :math:`\epsilon = (v w - q, p - u w)` and their Jacobian :math:`J` with respect to
:math:`(x, y, u, v)` give :math:`d^2 = \epsilon^\top (J J^\top)^{-1} \epsilon`.

Convention:
    - Argument order and direction as :func:`oneway_transfer_error`: ``H`` maps ``pts1`` to ``pts2``. Unlike the
      one-way transfer error, the distance accounts for noise in both images and does not depend on the scale
      of ``H``.
    - For an affine ``H`` the constraint is linear in the coordinates, and the distance is the exact geometric
      error.
    - An exact correspondence scores 0; a correspondence whose :math:`J J^\top` is singular scores ``inf``; a
      non-finite correspondence or homography gives NaN.
    - Computed in at least float32 and returned in the promoted dtype of the inputs, or in float32 when they are
      all integers.

Args:
    pts1: points in the first image with shape ``(B, N, 2)``, or homogeneous ``(B, N, 3)``.
    pts2: points in the second image with shape ``(B, N, 2)``, or homogeneous ``(B, N, 3)``.
    H: homographies with shape ``(B, 3, 3)``. Points with a leading dimension of 1 are scored against every
        homography.
    squared: if True (default), the squared distance is returned, else the distance.

Returns:
    the computed distance with shape ``(B, N)``.

See Also:
    - :func:`oneway_transfer_error`: the error in image 2 only, with all the noise on the second point.
    - :func:`symmetric_transfer_error`: the errors of ``H`` in image 2 and of its inverse in image 1, added.
    - :func:`~kornia.geometry.epipolar.sampson_epipolar_distance`: the same first-order error for a fundamental
      matrix.

z#points must have 2 or 3 coordinatesT©ÚkeepdimÚnan©Údimro   r,   r/   )r   é   r0   r2   )éþÿÿÿr/   r6   ).r1   r1   r4   ).r1   r3   r4   ).r1   r   r4   ).r3   r1   r4   ).r3   r3   r4   ).r3   r   r4   ).r   r1   r4   ).r   r3   r4   ).r   r   r4   )r   r   r7   r#   Úpromote_typesrU   Úfloat32Úis_floating_pointÚtoÚisfiniteÚallr   Úmasked_fillr&   ÚabsÚamaxr\   Ú	ones_likeÚsquarer^   ÚmathÚinfÚ
zeros_likeÚsqrt)r   r   r   r   rU   ÚworkÚ	out_dtypeÚfiniteÚxÚyÚuÚvÚscaleÚhÚpÚqÚwÚe1Úe2Újx1Újy1Újx2Újy2ÚaÚcÚbÚdetÚnumÚd2Úpositives   &&&&                          r(   Úsampson_homography_distancer�   õ   sÖ  € ô\ �qš/Ô*Ü�—‘˜B• 6Ñ)×FÐF¨d¯j©j¸­nÀÑ.FÐHmÔnÜ×Ò¤× 3Ò 3°D·J±JÀÇ
Á
Ó KÈQÏWÉWÓU€EÜ×Ò˜u¤e§m¡mÓ4€Dð ×0×0Ð0‘°d€IØ—‘˜“ §¡¨£ˆ$Ø‡z�z�"…~˜ÔÜ—’ Ó%×)Ñ)¨"°dÐ)Ó;ˆÜ.¨tÓ4×@Ñ@À&ÀÌ%ÐPUË,ÓWˆØ‡z�z�"…~˜ÔÜ—’ Ó%×)Ñ)¨"°dÐ)Ó;ˆÜ.¨tÓ4×@Ñ@À&ÀÌ%ÐPUË,ÓWˆØ��<˜˜f�€qØ��<˜˜f�€qð 	
�‰ˆT‹
€AØ�E‰E‹G�L‰L˜X¨tˆLÓ4€EØ	
ŒU�[Š[˜ ™ E¬5¯?ª?¸5Ó+AÓBÕ	BÀIÕN€AØ	ˆ,�˜!Õ˜a �o°Õ1Õ1°A°lµOÕC€AØ	ˆ,�˜!Õ˜a �o°Õ1Õ1°A°lµOÕC€AØ	ˆ,�˜!Õ˜a �o°Õ1Õ1°A°lµOÕC€AØ��U�Q�Y˜ �E�	ˆ€Bà�\•?Õ" Q |¥_Õ4°a¸L½/Õ6IÈAÈlÍOÕ6[ˆ€CØ��  |¥_Õ!4Õ4°a¸µoÈÈlÍOÕH[Õ6[ˆ€CØ�
‰
‹�s—z‘z“|Õ# a§h¡h£jÕ0€AØ�
‰
‹�s—z‘z“|Õ# a§h¡h£jÕ0€AØˆc�	�C˜#•IÕ€AØ
ˆa�%�!—(‘(“*Õ
€CØ
ˆb�i‰i‹k�/˜A �E B�J¨�OÕ
+¨a°"·)±)³+­oÕ
=€Cð 
Œu�{Š{˜3 ™7 C¬¯ª¸Ó)=Ó>Õ	>€BÜ	�Š�S˜A‘XœuŸš¨s´D·H±HÓ=¸rÓ	B€BÜ	�Š�R˜!‘VœU×-Ò-¨bÓ1°2Ó	6€BßØ˜‘6ˆÜ�[Š[˜¤5§;¢;¨x¸¼U¿_º_ÈRÓ=PÓ#Q×#VÑ#VÓ#XÐZ\Ó]ˆØ�5‰5�ÓÐr*   c          
      ó¤   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\         P                  /# )r   Úls1Úls2r   r   r!   rl   )r'   s   "r(   r)   r)   P  sK   € ÷ F5ñ F5Ü	�‰ðF5Ü!ŸL™LðF5Ü-2¯\©\ðF5ÜDHðF5ä
‡\�\ñF5r*   c                ó¬  € \        V. RO4       \        V . RO4       \        V. RO4       V P                  R,          w  rE\        P                  ! V ^^R7      w  rg\        P                  ! V^^R7      w  r‰\        P                  ! V P
                  VP
                  4      p
\        P                  ! \        P                  ! VP
                  V
4      \        P                  4      pVP                  V4      p\        V4      P                  V4      p\        V	4      P                  V4      p\        P                  P                  WÞ^R7      pVR	,          P                  R
RR7      pV\        P                  ! V^ 8„  V\        P                  ! V4      4      ,          P                  R4      pVR,          ^ 8„  p\        VP!                  WE^4      WÏ4      w  pp\        VP!                  WE^4      WÏ4      w  ppRVV,           ,          pV'       d
   V^,          pVV,          V,          VP#                  4       ( ,          p\%        VV4      P                  V
4      # )aù  Compute the mean distance of image-1 segment endpoints, mapped to image 2, from their lines.

``err = line_segment_transfer_error_one_way(ls1, ls2, H)`` takes segment correspondences ``(B, N, 2, 2)`` and
homographies ``(B, 3, 3)`` that map the first image to the second, and returns, per correspondence, ``(B, N)``,
the mean perpendicular distance in image 2 of the two endpoints of the image-1 segment, mapped by ``H``, from the
line through the image-2 segment (:cite:`homolines2001`). Unlike the point errors, it is unsquared by default;
``squared=True`` returns its square. A zero-length image-2 segment defines no line and scores 0 up to rounding
(up to 0.015 px in float32 for coordinates of a few hundred pixels). For point correspondences, use
:func:`oneway_transfer_error`.

Convention:
    - Argument order and direction as :func:`oneway_transfer_error`.
    - The image-2 line is scaled to unit :math:`(a, b)`, so the error is the mean perpendicular distance of
      the two mapped endpoints, in pixels.
    - An endpoint that ``H`` maps to infinity (:math:`w' = 0`) gives the segment the error ``inf``, as in
      :func:`oneway_transfer_error`, unless the image-2 segment has zero length; a NaN input stays NaN.

Args:
    ls1: line segment correspondences from the left images with shape
      ``(B, N, 2, 2)``.
    ls2: line segment correspondences from the right images with shape
      ``(B, N, 2, 2)``.
    H: Homographies with shape ``(B, 3, 3)``.
    squared: if True (default is False), the squared error is returned.

Returns:
    the computed error with shape ``(B, N)``.

See Also:
    - :func:`oneway_transfer_error`: the image-2 error of point correspondences.
    - :func:`find_homography_lines_dlt`: the homography that fits line segment correspondences.

ºNr   N©rr   Úchunks©rr   Trq   ç      à?r,   ©r-   ÚNÚ2r©   ).r4   r¢   r/   rt   r5   )r   r7   r#   Úchunkru   rU   rv   rx   r   ÚlinalgÚcrossÚnormr\   r~   ÚsqueezeÚ_line_endpoint_distancer]   Úisnanr   )rŸ   r    r   r   r-   r¨   Úps1Úpe1Úps2Úpe2r…   Ú
work_dtypeÚH_workÚps2_hÚpe2_hÚln2r‹   Úhas_lineÚdistance_startÚsingular_startÚdistance_endÚsingular_endÚerrorÚsingulars   &&&&                    r(   Ú#line_segment_transfer_error_one_wayrÁ   P  sÖ  € ôH �qš/Ô*Ü�sÒ0Ô1Ü�sÒ0Ô1Ø�9‰9�R�=�D€AÜ�{Š{˜3 A¨aÔ0�H€CÜ�{Š{˜3 A¨aÔ0�H€Cô
 ×#Ò# C§I¡I¨s¯y©yÓ9€IÜ×$Ò$¤U×%8Ò%8¸¿¹À)Ó%LÌeÏmÉmÓ\€JØ�T‰T�*Ó€FÜ)¨#Ó.×1Ñ1°*Ó=€EÜ)¨#Ó.×1Ñ1°*Ó=€EÜ
�,‰,×
Ñ
˜U¨qÐ
Ó
1€Cð �
�O× Ñ  R°Ð Ó6€Eà”—’˜U Q™Y¨¬u¯ª¸uÓ/EÓFÕF×
OÑ
OÐPRÓ
S€CØ�YÕ !Ñ#€Hä%<¸S¿X¹XÀaÈAÓ=NÐPVÓ%\Ñ"€N�NÜ!8¸¿¹À!ÈÓ9JÈFÓ!XÑ€L�,ð �> LÕ0Õ1€EßØ�q•ˆð  Õ-°Õ9¸U¿[¹[»]¸NÕJ€HÜ�e˜XÓ&×)Ñ)¨)Ó4Ð4r*   c          
      óÎ   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        \         P                  \         P                  3,          /# )r   Úpointsr   Úliner!   ©r#   r$   r   )r'   s   "r(   r)   r)   ™  sP   € ÷ Añ AÜ�L‰LðAÜ"Ÿ\™\ðAÜ16·±ðAä
Œ5�<‰<œŸ™Ð%Õ&ñAr*   c                ó„  € \        VP                  P                  4      ;_uu_ 4        \        V 4      P	                  VP
                  4      VP                  RR4      ,          pRRR4       XR,          pW2,          P                  R4      \        V4      ,          P                  4       V^ 8H  3#   + '       g   i     LS; i)a½  Return the distances ``(B, N)`` of ``H``-mapped ``points`` from the unit image-2 ``line``, and ``w' == 0``.

Maps without the OpenCV-style dehomogenization of :func:`transform_points`, which returns the numerator unchanged
for ``|w'| <= 1e-8``: a point mapped to infinity (``w' = 0``) is singular, as in :func:`oneway_transfer_error`
(#4881). The distance is ``|l . (x', y', w')| / |w'|``, so no mapped coordinate is formed that could overflow.
Nrt   r/   ).r   )
r	   rT   Útyper   rx   rU   Ú	transposeÚsumr   r|   )rÃ   r   rÄ   Úmappedr�   s   &&&  r(   r¯   r¯   ™  s‡   € ô 
˜AŸH™HŸM™M×	*Õ	*Ü.¨vÓ6×9Ñ9¸!¿'¹'ÓBÀQÇ[Á[ÐQSÐUWÓEXÕXˆ÷ 
+àˆv�€AØ�]×Ñ Ó#¤h¨q£kÕ1×6Ñ6Ó8¸!¸q¹&Ð@Ð@÷ 
+×	*ús   ¨<B/Â/B?	c                ó˜   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  /# )r   rŸ   r    r   r!   ©r#   r$   )r'   s   "r(   r)   r)   ©  sD   € ÷ _ñ _´·±ð _Ä5Ç<Á<ð _ÔTY×T`ÑT`ð _Ôej×eqÑeqñ _r*   c           
     óö   € \        WV4      pVR,          VR,          ,
          P                  RR7      p\        P                  ! V^ 8„  VP	                  4       \        P
                  ! V\        R4      4      4      # )a  Squared perpendicular distance, in pixels, of the mapped image-1 endpoints from the image-2 line.

:func:`line_segment_transfer_error_one_way` returns that pixel distance directly since #4867; a zero-length
image-2 segment defines no line, so its distance is infinite.
r¥   r�   ).r3   r4   ).r1   r4   r/   )rÁ   r­   r#   r\   r   r^   r&   )rŸ   r    r   ÚdistanceÚlengths   &&&  r(   Ú&_line_segment_squared_distance_one_wayrÐ   ©  s`   € ô 3°3¸QÓ?€HØ�)�n˜s 9�~Õ-×3Ñ3¸Ð3Ó;€FÜ�;Š;�v ‘z 8§?¡?Ó#4´e·o²oÀhÔPUÐV[ÓP\Ó6]Ó^Ð^r*   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úp1Úpoints2r!   rÌ   )r'   s   "r(   r)   r)   ´  s-   € ÷ 
9ñ 
9œŸ™ð 
9´·±ð 
9ÄÇÁñ 
9r*   c                ó$  € \         P                  ! V 4      p\         P                  ! W ) VR,          V ,          .RR7      p\         P                  ! WVR,          ) V ,          .RR7      p\         P                  ! W4.RR7      P	                  RR4      # )a8  DLT rows ``(..., 2N, 9)`` of homogeneous ``p1`` ``(..., N, 3)`` with unit last coordinate and ``points2``.

Two rows per correspondence, ``[0, -p1, y2 p1]`` and ``[p1, 0, -x2 p1]``, so that ``row . vec(H) = 0`` for
``points2 ~ H p1`` with ``H`` row-major; only the first two coordinates of ``points2`` are read.
r¥   ).ºr3   r   Nr/   ).ºr1   r3   Nrt   éýÿÿÿ)r#   r‚   ÚcatÚstackÚflatten)rÒ   rÓ   ÚzerosÚaxÚays   &&   r(   Ú_homography_rowsrÞ   ´  sw   € ô ×Ò˜RÓ €EÜ	�Š�E˜3 ¨Õ 1°BÕ 6Ð7¸RÔ	@€BÜ	�Š�B ¨Õ 1Ð1°BÕ6Ð7¸RÔ	@€BÜ�;Š;˜�x RÔ(×0Ñ0°°RÓ8Ð8r*   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# ©r   Úpoints1rÓ   r!   rÌ   )r'   s   "r(   r)   r)   Á  s2   € ÷ fñ f¤U§\¡\ð f¼E¿L¹Lð fÌUÏ\É\ñ fr*   c           	     ó€   € \        \        P                  ! V \        P                  ! V R,          4      .RR7      V4      # )zÇDLT rows ``(..., 2N, 9)`` of correspondences ``(..., N, 2)``, as :func:`_homography_rows`.

Each entry is the product the rows used to be written out with coordinate by coordinate, in fewer kernels.
r¥   ).ºNr3   Nr/   )rÞ   r#   rØ   r~   )rá   rÓ   s   &&r(   Ú_homography_design_rowsrä   Á  s1   € ô
 œEŸIšI w´·²ÀÈÕ@PÓ0QÐ&RÐXZÔ[Ð]dÓeÐer*   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# ©r   r;   Úx2r!   rÌ   )r'   s   "r(   r)   r)   É  s2   € ÷ 
Yñ 
YœuŸ|™|ð 
Y´·±ð 
YÄ%Ç,Á,ñ 
Yr*   c                ór  € \        W4      p\        VP                  \        P                  ! VP
                  \        P                  4      4      4      R,          pW3P                  4       P                  RRR7      P                  4       ,          P                  R^^4      P                  V P
                  4      # )a  Homographies ``(B, 3, 3)`` of unit Frobenius norm through four normalized correspondences.

``x1`` is homogeneous ``(B, 4, 3)`` with unit last coordinate and ``x2`` ``(B, 4, 2)`` or homogeneous. The null
vector of :func:`_homography_rows` comes from :func:`~kornia.geometry.solvers.homogeneous._null_space_lu`, in at
least float32. Unlike :func:`find_homography_dlt` there is no per-sample normalization, gauge solve or
``H[2, 2] = 1`` scaling: RANSAC's sampler normalizes once per call and scores unit-norm models.
Trn   r0   r/   )rÞ   r   rx   r#   ru   rU   rv   r   rÉ   ÚrsqrtÚreshape)r;   rç   ÚArŒ   s   &&  r(   Ú_four_point_homographyrì   É  s~   € ô 	˜Ó €AÜ�q—t‘tœE×/Ò/°·±¼¿¹ÓGÓHÓIÈ&ÕQ€AØ—‘“
—‘˜r¨4�Ó0×6Ñ6Ó8Õ8×AÑAÀ"ÀaÈÓK×NÑNÈrÏxÉxÓXÐXr*   c                ó˜   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  /# )r   r   r;   rç   r!   rÌ   )r'   s   "r(   r)   r)   Ö  s8   € ÷ $ñ $œŸ™ð $¬%¯,©,ð $¼E¿L¹Lð $ÌUÏ\É\ñ $r*   c                óÀ  € V P                   ^ ,          VP                   ^ ,          rCV P                  ^V,          ^4      VP                  ,          P                  V^V4      pVR,          p\	        V4      pVR,          V,          VR,          ,
          P                  4       VR,          V,          VR,          ,
          P                  4       ,           p\        W†^ 8H  4      # )aK  Squared one-way transfer errors ``(M, N)`` of homographies ``(M, 3, 3)`` on one set of correspondences.

``x1`` is homogeneous ``(N, 3)`` with unit last coordinate and ``x2`` ``(N, 2)``. ``H x1`` of every model is one
``(3M, 3) @ (3, N)`` product; the rest is :func:`oneway_transfer_error`'s formula, with its guard of ``w' = 0``.
©r4   r   ©r4   r1   ©r4   r3   )r7   rê   ÚTr]   r   r   r   )	r   r;   rç   ÚmÚnÚ	projectedr�   rL   rO   s	   &&&      r(   Ú_transfer_errorsrö   Ö  s«   € ð �7‰7�1�:�r—x‘x •{€qØ—‘˜1˜q�5 !Ó$ r§t¡tÕ+×1Ñ1°!°Q¸Ó:€IØ�$�€AÜ�a‹[€FØ�d�O˜fÕ$ r¨$¥xÕ/×7Ñ7Ó9¸YÀt½_ÈvÕ=UÐXZÐ[_ÕX`Õ=`×<hÑ<hÓ<jÕj€DÜ�d ™FÓ#Ð#r*   c          
      ó¤   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\         P                  /# rk   rl   )r'   s   "r(   r)   r)   ä  sD   € ÷ 5ñ 5Ü
�,‰,ð5Ü#Ÿl™lð5Ü/4¯|©|ð5ÜFJð5ä
‡\�\ñ5r*   c                ó�  € V P                   R,          p\        P                  ! \        P                  ! V P                  VP                  4      VP                  4      p\        P                  ! V\        P                  4      pV P                  W@P                   R,          4      P                  V4      pVP                  WAP                   R,          4      P                  V4      pVP                   R,          ^8X  d   \        V4      pVP                   R,          ^8X  d   \        V4      p\        VP                  V4      \        V4      V4      p	V'       d   T	M
\        V	4      p
\        P                  ! V P                   RR VP                   RR VP                   RR 4      pV
P
                  ! . VOVN5!  P                  V4      # )a  One-way transfer errors of many homographies on one set of correspondences, by :func:`_transfer_errors`.

``pts1`` and ``pts2`` have leading dimensions of size 1; homogeneous points are dehomogenized. Half precision is
computed in float32 and returned in the input dtype.
Nrt   r/   )r7   r#   ru   rU   rv   rê   rx   r   rö   r   r   Úbroadcast_shapes)r   r   r   r   Ú
num_pointsrU   r„   r;   rç   rO   rg   r7   s   &&&&        r(   r8   r8   ä  sF  € ð —‘˜B•€JÜ×Ò¤× 3Ò 3°D·J±JÀÇ
Á
Ó KÈQÏWÉWÓU€EÜ×Ò˜u¤e§m¡mÓ4€DØ	�‰�j§*¡*¨R¥.Ó	1×	4Ñ	4°TÓ	:€BØ	�‰�j§*¡*¨R¥.Ó	1×	4Ñ	4°TÓ	:€BØ	‡x�x�…|�qÔÜ,¨RÓ0ˆØ	‡x�x�…|�qÔÜ,¨RÓ0ˆÜ˜AŸD™D ›JÔ(EÀbÓ(IÈ2ÓN€Dß‰$œ}¨TÓ2€CÜ×"Ò" 4§:¡:¨c¨r ?°D·J±J¸sÀ°OÀQÇWÁWÈSÈbÀ\ÓR€EØ�;Š;Ð*˜Ð*˜zÓ*×-Ñ-¨eÓ4Ð4r*   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# ræ   rÌ   )r'   s   "r(   r)   r)   û  s-   € ÷ ñ œŸ™ð ¬%¯,©,ð ¼5¿<¹<ñ r*   c                ó‚  € V P                   ^ ,          pV P                  ^	^V,          4      pV P                  VRRV13&   VR,          V ,          P                  ) VRRV13&   V P                  VRV^V,          13&   VR,          V ,          P                  ) VRV^V,          13&   V P                  VR^V,          R13&   V# )a<  Per-correspondence monomials ``(9, 3N)`` of the one-way transfer error, for RANSAC's sampling loop only.

``vec(H) @ basis`` is ``[P_0 - u P_2 | P_1 - v P_2 | P_2]`` for ``P = H x1`` and ``x2 = (u, v)``, with ``x1``
homogeneous ``(N, 3)``. Folding the subtraction into the product is about 10% faster than
:func:`_transfer_errors` in RANSAC's loop on CPU (2048 models x 500 points: 6.6 against 7.2 ms) and 20-35 us per
CUDA batch of 512-8192 models; it is accurate on normalized points, but in pixel units its float32 error was 2.5x
that of :func:`oneway_transfer_error`.
:r1   rs   NN:é   é	   N:rs   rý   N)r4   rÖ   )r4   rÕ   )r7   Ú	new_zerosrò   )r;   rç   rô   Úbasiss   &&  r(   Ú_transfer_basisr  û  sº   € ð 	�‰��€AØ�L‰L˜˜A �EÓ"€EØ—T‘T€Eˆ#ˆr�ˆrˆ'�NØ˜&•z B•×)Ñ)Ð)€Eˆ#ˆr�ˆrˆ'�NØŸD™D€Eˆ#ˆq�1�q•5ˆyˆ.ÑØ  �j¨2�o×0Ñ0Ð0€Eˆ#ˆq�1�q•5ˆyˆ.ÑØŸ$™$€Eˆ#ˆq�1�u‰wˆ,ÑØ€Lr*   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   r   r   r!   rÌ   )r'   s   "r(   r)   r)     s2   € ÷ Yñ YœEŸL™Lð Y´·±ð YÄ%Ç,Á,ñ Yr*   c                ó8  € VP                   ^,          ^,          pV P                  ^4      V,          pVRRV13,          P                  4       VRV^V,          13,          P                  4       ,           VR^V,          R13,          P                  4       ,          # )zfSquared one-way transfer errors ``(M, N)`` of homographies ``(M, 3, 3)`` from :func:`_transfer_basis`.r4   N)r7   rÚ   r   )r   r   rô   rg   s   &&  r(   Ú_transfer_from_basisr    s|   € à�‰�A�˜!Õ€AØ
�)‰)�A‹,˜Õ
€CØ��2�A�2��J×ÑÓ # a¨¨Q°­U¨ lÕ"3×":Ñ":Ó"<Õ<ÀÀAÀqÈ1ÅuÁwÀJÅ×@VÑ@VÓ@XÕXÐXr*   c                ó(  € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        \         P                  ,          R\        R\        \
        \         P                  3,          R\        R\         P                  /# )	r   r   r;   rç   ÚmaskÚlossÚscale2Úitersr!   )r#   r$   r   Ústrr   r&   Úint)r'   s   "r(   r)   r)     s‰   € ÷ Iñ IÜ‡|�|ðIä�‰ðIô 	�‰ðIô ”5—<‘<Õ
 ð	Iô
 ðIô ”%œŸ™Ð%Õ&ðIô ðIô ‡\�\ñIr*   c           
     óž  aaaaaaaa€ V P                   ^ ,          oV P                  V P                  r‡S^ 8„  ;'       d2    VP                  R8H  ;'       d    \        P
                  ! 4       '       * p	V	'       dN   S^8X  dG   SeC   SP                  \        P                  8X  d$   SS^ ,          ,          SS^ ,          ,          Ruooo\        P                  ! ^WxR7      p
\        P                  ! ^	WxR7      oS^,          oV P                  ^4      pW»P                  4       P                  ^RR7      P                  4       ,          p\        P                  ! S^^3RWxR7      pR VVVVVVVV3R llpV! V4      w  rïp\        V4       EF°  p\        P                  P                  VR,          WÊ,          ,           VR,          4      ^ ,          ) pVVV,          R,          ,           pVVP                  4       P                  ^RR7      P                  4       ,          pV	'       Edp   V^,           V8X  Eda   VP!                  S^^4      SP"                  ,          pVR,          pSe0   \        P$                  ! S^ 8g  V\        P&                  ! V4      4      pVR,          VR,          ,          SP"                  ,
          P                  4       P                  ^4      pSR	8X  d   \        P(                  ! VS,          4      MA\        P*                  ! V\        P,                  ! SVP                  VP                  R7      4      pSf   TMVS,          P                  ^4      pVV8  p\        P$                  ! VR,          VV4      P!                  S^^4      u # V! V4      w  pppVV8  R,          p\        P$                  ! VR,          VV4      \        P$                  ! VR,          VV4      rû\        P$                  ! VVV4      \        P$                  ! VVV4      ppV\        P$                  ! VR
R4      ,          pEK³  	  VP!                  S^^4      # )aí  Levenberg-Marquardt on the one-way transfer error, batched over homographies ``(K, 3, 3)``.

In the spirit of PoseLib's ``refine_homography``: steps are taken in the eight-dimensional orthogonal complement of
the unit-norm ``vec(H)`` and renormalized. ``x1`` is homogeneous ``(N, 3)`` and ``x2`` ``(N, 2)``, normalized by
the caller; the loss, ``mask`` and step acceptance are those of
:func:`~kornia.geometry.epipolar.fundamental._refine_fundamental_lm`. For RANSAC, under ``torch.no_grad``.
ÚcpuN)rU   rT   Trn   gü©ñÒMbP?c                ó¬   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  \         P                  3,          /# )r   rŒ   r!   rÅ   )r'   s   "r(   r)   Ú+_refine_homography_lm.<locals>.__annotate__1  s:   € ÷ Qñ QœEŸL™Lð Q¬U´5·<±<ÄÇÁÌuÏ|É|Ð3[Õ-\ñ Qr*   c           	      ó\  <€ V \         P                  ! V R,          ^ 8¬  RR4      S,          ,           pWP                  4       P                  ^RR7      P	                  4       ,          pS^VR,          ,          VR,          ,          ,
          R	,          p\         P
                  ! V R,          V.^4      P                  P                  S^^4      pVSP                  ,          P                  S^	^R
4      pRSf
   VR,          M<\         P                  ! S^ 8g  VR,          \         P                  ! VR,          4      4      ,          pVR,          VR,          ,          pVSP                  ,
          P                  ^4      pVR,          VR,          VR,          ,          ,
          VR,          ,          P                  ^4      pVR RSP                  ^ ,          13,          P                  4       VR SP                  ^ ,          R13,          P                  4       ,           p	\        V	SS4      w  r«Se   V
S,          VS,          rºV\         P
                  ! Wª.^4      R,          ,          p\         P
                  ! WÈP                  ,          WÇR,          ,          .^4      VP                  ^4      V3# )r4   g      ð?Trn   N)r4   :é   rþ   Ng      ð¿)r4   r4   N)r4   Nr4   )r4   r4   ºNr  Nr/   )r4   r1   r   )r4   r1   r¢   ©r4   N)r4   ºr3   NNr¢   )r4   r  :r   rs   N©r4   NNr6   )r#   r\   r   rÉ   ré   rØ   ÚmTrê   rò   r~   rÚ   r7   r   )rŒ   rŠ   ÚtangentÚstackedÚPÚizÚuvÚrÚJÚr2r�   ÚrhoÚJwÚKÚeye9Úlastr  r  r  r;   rç   s   &            €€€€€€€€r(   Únormal_equationsÚ/_refine_homography_lm.<locals>.normal_equations1  s
  ø€ à”—’˜A˜f�I¨™N¨C°Ó6¸Õ=Õ=ˆØ—‘“
—‘˜q¨$�Ó/×5Ñ5Ó7Õ7ˆØ˜!˜a 
�mÕ+¨a°
­mÕ;Õ;¸XÕFˆÜ—)’)˜Q˜z�]¨GÐ4°aÓ8×;Ñ;×CÑCÀAÀrÈ1ÓMˆØ�r—t‘t�^×$Ñ$ Q¨¨1¨bÓ1ˆð  $¢,�A�g–J´E·K²KÀÈÁ	È1ÈWÍ:ÔW\×WfÒWfÐghÐipÕgqÓWrÓ4sÕtˆØˆx�[˜2˜g�;Õ&ˆØ�"—$‘$�Y×Ñ Ó"ˆØ�	�l˜R �[¨1¨Z­=Õ8Õ8¸B¸}Õ<MÕM×VÑVÐWXÓYˆØˆq�-�B—H‘H˜Q•K�-ÐÕ ×'Ñ'Ó)¨A¨a°·±¸!µ±Ð.>Õ,?×,FÑ,FÓ,HÕHˆÜ˜b $¨Ó/‰ˆØÒØ˜•X˜s T�zˆsØ”—’˜A˜6 1Ó% gÕ.Õ.ˆÜ�yŠy˜"Ÿt™t�) R¨I­,Õ%6Ð7¸Ó;¸S¿W¹WÀQ»ZÈÐPÐPr*   Úcauchygš™™™™™¹?g      $@).r  ).:r  NNr0   rï   )r4   r¢   r  r  ©r4   r4   r1   )r4   r1   r1   )r7   rU   rT   rÇ   r#   Úis_grad_enabledr%   rZ   rÚ   r   rÉ   ré   ÚfullÚranger«   Úsolve_exrê   rò   r\   r~   Úlog1pÚfminÚ	as_tensor) r   r;   rç   r  r  r  r	  rU   rT   r  Úeye8rŒ   Údampingr$  ÚsystemÚcostr  Ú	iterationÚdeltaÚh_newÚ
projectionÚdivisorr  r  Úcost_newÚacceptedÚ
system_newÚtangent_newÚacceptr!  r"  r#  s    &fffff&                      @@@r(   Ú_refine_homography_lmr=    sL  ÿ€ ð  	
�‰��
€AØ—G‘G˜QŸX™Xˆ6Ø
ˆa‰%×
HÐ
H�F—K‘K 5Ñ(×
HÐ
H´×1FÒ1FÓ1HÔ-H€Cß
ˆq�AŒv˜$Ò*¨t¯z©z¼U¿Z¹ZÔ/GØ˜$˜q�'•{ B t¨A¥w¥K°ˆˆˆB�Ü�9Š9�Q˜eÔ3€DÜ�9Š9�Q˜eÔ3€DØ��7€DØ	�	‰	�!‹€AØ	�H‰H‹J�N‰N˜1 dˆNÓ+×1Ñ1Ó3Õ3€AÜ�jŠj˜!˜Q ˜ D°ÔE€G÷Q÷ Qñ* -¨QÓ/Ñ€F�'Ü˜5—\ˆ	Ü—‘×&Ñ& v¨g¥¸½Õ'GÈÐPWÍÓYÐZ[Õ\Ð\ˆØ�W˜u•_ fÕ-Õ-ˆØ˜Ÿ™›×*Ñ*¨1°dÐ*Ó;×AÑAÓCÕCˆßˆ3�9˜q•= EÕ)ØŸ™ q¨!¨QÓ/°"·$±$Õ6ˆJØ  Õ&ˆGØÒÜŸ+š+ d¨a¡i°¼%¿/º/È'Ó:RÓS�Ø˜UÕ# g¨gÕ&6Õ6¸¿¹Õ=×EÑEÓG×KÑKÈAÓNˆBð ˜8Ô#ô —’˜B �KÔ(ä—Z’Z ¤E§O¢O°FÀ"Ç(Á(ÐSU×S\ÑS\Ô$]Ó^ð ð
  $š|™°°tµ×@Ñ@ÀÓCˆHØ $‘ˆHÜ—;’;˜x¨Õ0°%¸Ó;×CÑCÀAÀqÈ!ÓLÒLÙ,<¸UÓ,CÑ)ˆ
�H˜kØ˜T‘/ =Õ1ˆÜ—+’+˜f W�o¨u°aÓ8¼%¿+º+ÀfÈWÅoÐW_ÐaeÓ:fˆ4ÜŸ+š+ f¨j¸&ÓAÄ5Ç;Â;ÈvÐWbÐdkÓCl�ˆØœEŸKšK¨°°TÓ:Õ:‹ñ- "ð. �9‰9�Q˜˜1ÓÐr*   c          
      óº   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        R\         P                  /# )r   rá   rÓ   ÚweightsÚsolverr!   )r#   r$   r   r
  )r'   s   "r(   r)   r)   a  sP   € ÷ Fñ FÜ�\‰\ðFÜ$)§L¡LðFÜ;CÄEÇLÁLÕ;QðFÜbeðFä
‡\�\ñFr*   c                ó¤  € \        W.4      w  rEVe%   \        VP                  V P                  4      4      p\        V 4      \        V4      r\	        V P
                  P                  4      ;_uu_ 4        \        WV4      w  rgp\        WbV\        V4      W4V P                  4      P                  V4      uuRRR4       #   + '       g   i     R# ; i)aš  Estimate a homography from four or more weighted point correspondences by the normalized DLT.

``H = find_homography_dlt(points1, points2)`` takes correspondences ``(B, N, 2)``, ``N >= 4``, and returns the
homography ``(B, 3, 3)`` that maps ``points1`` to ``points2``, :math:`x_2 \sim H x_1`: the least-squares
solution of the Hartley-normalized DLT system, solved with ``solver``, and the source-to-destination pixel
homography that :func:`~kornia.geometry.transform.warp_perspective` takes. ``weights`` ``(B, N)`` weight each
correspondence's equations. It is not robust to wrong correspondences: with outliers, use
:class:`~kornia.geometry.ransac.RANSAC`. For exactly four points in closed form, use
:func:`~kornia.geometry.transform.get_perspective_transform`; for line segments,
:func:`find_homography_lines_dlt`.

Convention:
    - ``H`` is scaled so that ``H[2, 2] = 1`` by :func:`~kornia.geometry.epipolar.normalize_transformation`,
      which leaves it at its unnormalised scale when ``|H[2, 2]|`` is at most ``1e-8``;
      :ref:`two-view-conventions` compares this with OpenCV.
    - ``weights`` multiply each correspondence's squared algebraic residual: a weight of 0 removes the
      correspondence from the equations, and only relative weights matter.
    - ``solver="lu"`` and ``"svd"`` give the same homography on exact data, to roundoff scaled by the
      conditioning of the system; on noisy data they solve different least-squares problems and differ.
    - A caller's autocast region does not change the fit.

.. note::
    On MPS, the default ``solver="lu"`` needs torch 2.10 or later and ``solver="svd"`` runs from torch 2.5.1;
    see :ref:`MPS linear algebra <mps-linear-algebra>`.

Args:
    points1: A set of points in the first image with a tensor shape ``(B, N, 2)``.
    points2: A set of points in the second image with a tensor shape ``(B, N, 2)``.
    weights: Tensor containing the weights per point correspondence with a shape of ``(B, N)``.
      Zero-weight points are excluded from the DLT equations and Hartley normalization.
    solver: variants: svd, lu.


Returns:
    the computed homography matrix with shape ``(B, 3, 3)``. A batch element whose weighted DLT system is
    not finite, because a weight or a point is not finite (zero-weight points included) or an entry overflows,
    is NaN for both solvers and on every device; the other elements are unaffected. If the SVD of
    ``solver="svd"`` fails to converge on a finite system, the whole batch is NaN and a ``RuntimeWarning`` is
    issued.

See Also:
    - :func:`find_homography_dlt_iterated`: the same fit re-weighted by the transfer error over a few solves.
    - :func:`find_homography_lines_dlt`: a homography from line segment correspondences.
    - :func:`~kornia.geometry.transform.get_perspective_transform`: the exact homography of four points, in
      closed form.
    - :class:`~kornia.geometry.ransac.RANSAC`: a homography robust to wrong correspondences.
    - :func:`~kornia.geometry.epipolar.find_fundamental`: the two-view model of a general scene instead of a
      plane.
    - :func:`~kornia.geometry.epipolar.find_essential`: the two-view model of calibrated cameras in a general
      scene.
    - :func:`~kornia.geometry.solvers.find_affine`: an affine map, the special case with bottom row
      ``[0, 0, 1]``.
    - :func:`~kornia.geometry.calibration.solve_pnp_dlt`: the DLT for 3D-2D correspondences, a camera pose
      rather than a homography.

N)
r
   r   rx   rU   r	   rT   rÇ   Ú_homography_dlt_systemÚ_homography_from_dlt_systemÚ_inverse_normalization)	rá   rÓ   r?  r@  rT   rU   rë   Ú
transform1Ú
transform2s	   &&&&     r(   Úfind_homography_dltrG  a  s¡   € ôv *¨7Ð*<Ó=�M€FàÒÜ# G§J¡J¨w¯}©}Ó$=Ó>ˆä(¨Ó1Ô3DÀWÓ3MˆWä	˜GŸN™N×/Ñ/×	0Õ	0Ü$:¸7ÈWÓ$UÑ!ˆ�zÜ*Ø˜
Ô$:¸:Ó$FÈÐX_×XeÑXeó
ç
‰"ˆU‹)÷	 
1×	0×	0Ó	0ús   Á3A B>Â>C	c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   Ú	transformr!   rÌ   )r'   s   "r(   r)   r)   ª  s&   € ÷ `ñ `¤e§l¡lð `´u·|±|ñ `r*   c           
     ó–   € \        V 4      w  r\        P                  ! VR,          V\        P                  ! V\	        R4      4      4      # )a	  Invert a Hartley normalization, NaN where it is singular.

A point set whose mean radius overflows gets a zero scale and a singular normalization. Its homography
is undefined, so it is NaN rather than built from the identity ``safe_inverse_with_mask`` substitutes.
rp   ).NN)r   r#   r\   r^   r&   )rI  ÚinverseÚvalids   &  r(   rD  rD  ª  s:   € ô ,¨IÓ6�N€GÜ�;Š;�u˜_Õ-¨w¼¿ºÈÔQVÐW\ÓQ]Ó8^Ó_Ð_r*   c                ó  € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        \         P                  \         P                  \         P                  3,          /# )r   rá   rÓ   r?  r!   )r#   r$   r   r   )r'   s   "r(   r)   r)   ´  sU   € ÷ %ñ %Ü�\‰\ð%Ü$)§L¡Lð%Ü;CÄEÇLÁLÕ;Qð%ä
Œ5�<‰<œŸ™¤u§|¡|Ð3Õ4ñ%r*   c                óH  € V P                   VP                   8w  db   \        R\        V P                   4       R\        VP                   4       R2\        V P                   4      \        VP                   4      R7      hV P                  ^8w  g   V P                   ^,          ^8  d;   \        R\        V P                   4       R2\        V P                   4      . ROR7      h\	        V . RO4       \	        V. RO4       Vez   VP                   V P                   R,          8w  dX   \        R	\        V P                   R,          4       R
\        VP                   4       R2\        VP                   4      RR.R7      h\        WR7      w  r4\        WR7      w  rV\        W54      pWtV3# )zSBuild the weighted-normalized DLT design matrix and its two normalizing transforms.ú2points1 and points2 must have the same shape, got ú and Ú.©Úactual_shapeÚexpected_shapez?points1 and points2 must have shape (B, N, 2) with N >= 4, got r-   r¨   r¢   ú!weights must have shape (B, N) = ú, got ©r?  )r-   zN >= 4r©   )r-   r¨   r©   )r7   r   ÚlistÚndimr   r   rä   )rá   rÓ   r?  Úpoints1_normrE  Úpoints2_normrF  rë   s   &&&     r(   rB  rB  ´  si  € ð ‡}�}˜Ÿ™Ô%ÜØ@ÄÀgÇmÁmÓATÐ@UÐUZÔ[_Ð`g×`mÑ`mÓ[nÐZoÐopÐqÜ˜gŸm™mÓ,Ü §¡Ó.ô
ð 	
ð
 ‡|�|�qÔ˜GŸM™M¨!Õ,¨qÔ0ÜØMÌdÐSZ×S`ÑS`ÓNaÐMbÐbcÐdÜ˜gŸm™mÓ,Ú/ô
ð 	
ô
 �w¢Ô0Ü�w¢Ô0àÒ˜wŸ}™}°·±¸bÕ0AÔAÜØ/´°W·]±]À2Õ5FÓ0GÐ/HÈÌtÐT[×TaÑTaÓObÐNcÐcdÐeÜ˜gŸm™mÓ,Ø ˜:ô
ð 	
ô
  0°ÔIÑ€LÜ/°ÔIÑ€Lä Ó;€AØ˜*Ð$Ð$r*   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# ©r   Únormalr!   rÌ   )r'   s   "r(   r)   r)   Ô  s&   € ÷ Rñ RœuŸ|™|ð R´·±ñ Rr*   c           
     ó–  € V P                   \        P                  8X  d   \        P                  M\        P                  pV P	                  V4      p V P                  4       P                  ^4      P                  R4      p\        P                  ! VR,          V \        P                  ! V 4      4      p \        P                  P                  V P                  4       4      w  r4pVP                  RRR7      P                  4       p\        P                  ! V4      P                   pVR,          P#                  R4      VP%                  R4      P'                  V4      \        P                  ! V4      P(                  R,          ,          8„  pW%V P*                  R,          8H  ,          V,          p	\        P                  ! V	R,          V R	,          \        P,                  ! ^V P.                  VR7      4      p
\        P                  ! V	R
,          V R,          ) \        P                  ! V R,          4      4      p\        P                  P1                  W«4      ^ ,          p\        P2                  ! V\        P4                  ! VR,          4      .R4      p\        P                  ! V	R
,          V\        P6                  ! V\9        R4      4      4      # )a#  Null vector of a ``(B, 9, 9)`` DLT normal matrix whose LU has only its last pivot zero, else NaN.

Only the last pivot being zero means the first eight columns are independent, so the null vector has
``h[8] != 0`` and, the matrix being symmetric, its leading 8x8 block is non-singular: fixing ``h[8] = 1``
leaves that block's system, solved with ``normal`` itself so the result stays differentiable. Roundoff
can leave a degenerate matrix with tiny non-zero pivots instead, so the first eight must also be above
``sqrt(eps)`` relative to the largest. On the integer keypoints of the tests (exact identities, shifts
and 90-degree rotations) the smallest stayed above ``4e-2``; on coincident or collinear points it was
below ``1e-6``. Non-finite matrices are factorized as zeros (see #4770) and give NaN.
)Údim1Údim2r¦   rS   rp   r/   r  rt   )r4   r  )r4   r  r  r  )r4   r  r  )r4   rã   )rU   r#   Úfloat64rv   rx   ry   rÚ   rz   r\   r‚   r«   Úlu_factor_exrY   Údiagonalr|   rW   ÚtinyÚaminr}   Ú	clamp_minr    r7   rZ   rT   r+  rØ   r~   r^   r&   )r^  rµ   r†   Úlur`   Úinford  re  ÚleadingÚrank8ÚblockÚrhsÚheadÚnulls   &             r(   Ú_rank8_null_vectorrp  Ô  sç  € ð #)§,¡,´%·-±-Ô"?”—’ÄUÇ]Á]€JØ�Y‰Y�zÓ"€FØ�_‰_Ó×&Ñ& qÓ)×-Ñ-¨bÓ1€FÜ�[Š[˜ Õ.°¼×8HÒ8HÈÓ8PÓQ€FÜ—,‘,×+Ñ+¨F¯M©M«OÓ<�K€Bˆ4Ø�{‰{ ¨ˆ{Ó,×0Ñ0Ó2€HÜ�;Š;�zÓ"×'Ñ'€DØ�u�o×"Ñ" 2Ó&¨¯©°rÓ):×)DÑ)DÀTÓ)JÌUÏ[Ê[ÐYcÓMd×MhÑMhÐloÕMoÕ)oÑo€GØ˜fŸl™l¨2Õ.Ñ.Õ/°'Õ9€Eô �KŠK˜˜mÕ,¨f°YÕ.?ÄÇÂÈ1ÐU[×UbÑUbÐjtÔAuÓv€EÜ
�+Š+�e˜G•n v¨hÕ'7Ð&7¼×9IÒ9IÈ&ÐQYÕJZÓ9[Ó
\€CÜ�<‰<× Ñ  Ó,¨QÕ/€DÜ�9Š9�dœEŸOšO¨D°­KÓ8Ð9¸2Ó>€DÜ�;Š;�u˜W•~ t¬U¯_ª_¸TÄ5ÈÃ<Ó-PÓQÐQr*   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# r]  rÌ   )r'   s   "r(   r)   r)   ñ  s&   € ÷ Sñ SœUŸ\™\ð S¬e¯l©lñ Sr*   c           
     ón  € V P                  4       P                  ^4      P                  R4      p\        P                  ! VR,          V \        P
                  ! V 4      4      p \        VP                  4       4      w  r4p\        Y$TR4      P                  T P                   4      p\        P                  ! TR,          T\        P                  ! T\        R4      4      4      #   \         dH    \        P                  ! R\        ^R7       \        P                  ! T R,          \        R4      4      u # i ; i)a«  Right singular vector of the smallest singular value of each ``(B, 9, 9)`` matrix, NaN where it is undefined.

A matrix with a non-finite entry has no null vector, and the backends disagree on what its SVD returns:
CPU ``torch.linalg.svd`` raises for the whole batch, while CUDA can return a finite vector, such as a basis
vector, for a matrix with a single NaN entry. Such matrices are decomposed as zeros and their vectors are
replaced by NaN, so on every backend the finite matrices keep their vectors and the others are NaN, as with
the LU solver (#4770). If the SVD still fails on a finite batch, every vector is NaN and a warning is issued;
there is no partial result to keep.
zSVD did not converge)Ú
stacklevelrp   r/   r  r0   r  )ry   rÚ   rz   r#   r\   r‚   r   rY   ÚRuntimeErrorÚwarningsÚwarnÚRuntimeWarningr^   r&   r   rx   rU   )r^  r†   Úsafer`   ÚSÚVro  s   &      r(   Ú_svd_null_vectorr{  ñ  sá   € ð �_‰_Ó×&Ñ& qÓ)×-Ñ-¨bÓ1€FÜ�;Š;�v˜mÕ,¨f´e×6FÒ6FÀvÓ6NÓO€Dð=ä*¨4¯;©;«=Ó9‰ˆˆaô " $¨1¨bÓ1×4Ñ4°V·\±\ÓB€DÜ�;Š;�v˜g•¨¬e¯oªo¸dÄEÈ%ÃLÓ.QÓRÐRøô ô =Ü�ŠÐ,¬nÈÕKÜ�Š˜v f�~¬u°U«|Ó<Ò<ð=ús   Á#C" Ã"AD4Ä3D4c                ó  € V ^8„  d   QhR\         P                  R\        \         P                  ,          R\         P                  R\         P                  R\        R\         P                  R\         P
                  R\         P                  /# )	r   rë   r?  rE  Útransform2_invr@  rT   rU   r!   )r#   r$   r   r
  rT   rU   )r'   s   "r(   r)   r)   	  sƒ   € ÷ _,ñ _,Ü‡|�|ð_,ä”e—l‘lÕ#ð_,ô —‘ð_,ô —L‘Lð	_,ô
 ð_,ô �L‰Lð_,ô �;‰;ð_,ô ‡\�\ñ_,r*   c           
     ó0  € RpV P                   ^,          ^,          pVf   Rp	M°\        VP                   4      ^8X  d%   VP                   V P                   ^ ,          V38X  gQ   \        RV P                   ^ ,          V. R\        VP                   4       R2\        VP                   4      RR.R7      hVP	                  ^^R	7      P                  ^4      p	VR
8H  ;'       d    V^8H  p
V
'       g>   V	f   V P                  RR4      V ,          MV P                  RR4      V	,          V ,          p VR8X  d   \        V 4      P                  R^^4      pEM.VR
8X  Ed!   V
'       g”   \        P                  ! V P                   ^ ,          V P                   ^,          WVR7      p\        WÀ4      w  rÞp\        P                  ! VR,          V\        V 4      P                  VP                  4      R,          4      pEMqV	f   T MW	P                  RR4      ,          pVP!                  4       pVP#                  ^4      P%                  R4      p\        P                  ! VV\        P&                  ! V4      4      pV\        P(                  8X  d   \        P(                  M\        P*                  pVP-                  4       P                  V4      p\/        VRR7      R,          pVVP1                  RRR7      ,          pVP3                  4       P5                  RR	7      p\        P6                  ! ^VR7      P9                  V P                   ^ ,          R4      pVVVR,          8¬  P                  VP                  4      ,           pVP;                  RVR,          P9                  R^R4      4      pVP;                  RVR,          P9                  R^^4      4      P=                  R4      ) p\        VV4      w  rÞpVP=                  R4      pVVP;                  RVR,          4      ,          P                  VP                  4      p\        P                  ! VR,          VVP;                  RV4      4      p\        P6                  ! ^	VR7      P9                  V P                   ^ ,          R4      pVVVR,          8„  P                  VP                  4      ,
          P?                  ^ ^4      p\        P                  ! VVR,          8H  \        P@                  ! VVP                  R7      VP;                  RV4      4      p\        P                  ! VR,          V\        PB                  ! V\E        R4      4      4      pVPG                  R^^4      pM\H        hW;V,          ,          p\K        W·4      # )z¦Solve the (weighted) DLT system of :func:`_homography_dlt_system` and denormalize the homography.

The operand order matches the original single-call implementation.
ç:Œ0âŽyE>NrU  rV  rQ  r-   r¨   rR  r¥   rh  ÚsvdrS   T)Úrank_deficient_basisrq   )rT   )rU   rp   rt   r/   r  r6   r0   r  )&r7   Úlenr   rX  Úrepeat_interleaveÚ	unsqueezerÈ   r{  r]   r#   Úonesr   r\   rp  rx   rU   ry   rÚ   rz   r‚   rb  rv   rY   r   r­   r|   ÚargmaxÚarangeÚexpandÚgatherr®   Úclampr~   r^   r&   rê   ÚNotImplementedErrorr   )rë   r?  rE  r}  r@  rT   rU   r    rú   Úw_fullÚ
minimal_lur   r-   Úsolr`   rL  ÚAwÚfinite_entriesr†   Úgauge_dtypeÚdesignro  ÚgaugeÚretainedÚselectedÚ	positionsÚsources   &&&&&&&                    r(   rC  rC  	  s^  € ð €CØ—‘˜•˜q•€JØ‚à‰ô �G—M‘MÓ" aÔ'¨G¯M©M¸a¿g¹gÀa½jÈ*Ð=UÔ,UÜØ3°Q·W±W¸QµZÀÐ4LÐ3MÈVÔTXÐY`×YfÑYfÓTgÐShÐhiÐjÜ! '§-¡-Ó0Ø # S˜zôð ð
 ×*Ñ*¨1°!Ð*Ó4×>Ñ>¸qÓAˆð
 ˜4‘×3Ð3 J°!¡O€JßØ'-¢~ˆA�K‰K˜˜BÓ !Ö#¸A¿K¹KÈÈBÓ<OÐRXÕ<XÐ\]Õ;]ˆà�„Ü˜QÓ×$Ñ$ R¨¨AÓ.ŠØ	�4�ßÜ—
’
˜1Ÿ7™7 1�: q§w¡w¨q¥z¸&ÔNˆAÜ0°Ó6‰MˆC�Eô —+’+˜e MÕ2°CÔ9KÈAÓ9N×9QÑ9QÐRU×R[ÑR[Ó9\Ð]fÕ9gÓhŠCð ’n‘¨!×.>Ñ.>¸rÀ2Ó.FÕ*FˆBð  Ÿ[™[›]ˆNØ#×+Ñ+¨AÓ.×2Ñ2°2Ó6ˆFÜ—’˜^¨R´×1AÒ1AÀ"Ó1EÓFˆBØ+0´E·M±MÔ+Aœ%Ÿ-š-ÄuÇ}Á}ˆKØ—Y‘Y“[—^‘^ KÓ0ˆFô " &¸tÔDÀVÕLˆDØ˜$Ÿ)™)¨°D˜)Ó9Õ9ˆDØ—H‘H“J×%Ñ%¨"Ð%Ó-ˆEÜ—|’| A¨fÔ5×<Ñ<¸Q¿W¹WÀQ½ZÈÓLˆHØ 8¨u°W­~Ñ#=×"AÑ"AÀ(Ç.Á.Ó"QÕQˆHØ—y‘y  X¨gÕ%6×%=Ñ%=¸bÀ!ÀRÓ%HÓIˆHØ—‘˜2˜u ]Õ3×:Ñ:¸2¸qÀ!ÓDÓE×MÑMÈbÓQÐQˆAÜ0°°HÓ=‰MˆC�EØ—+‘+˜b“/ˆCð ˜4Ÿ;™; r¨5°­>Ó:Õ:×>Ñ>¸s¿y¹yÓIˆDÜ—+’+˜e G�n¨c°4·;±;¸rÀ8Ó3LÓMˆCÜŸš Q¨vÔ6×=Ñ=¸a¿g¹gÀa½jÈ"ÓMˆIØ 9¨u°W­~Ñ#=×"AÑ"AÀ)Ç/Á/Ó"RÕR×YÑYÐZ[Ð]^Ó_ˆFÜ—+’+Ø˜U 7�^Ñ+¬U¯_ª_¸YÈcÏiÉiÔ-XÐZ]×ZdÑZdÐegÐioÓZpóˆCô —+’+˜f W�o¨s´E·O²OÀCÌÈuËÓ4VÓWˆCØ�K‰K˜˜A˜qÓ!‰ä!Ð!Ø˜j�.Õ)€AÜ# AÓ+Ð+r*   c                ó°   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\         P                  /# )r   rá   rÓ   r?  Úsoft_inl_thÚn_iterr!   ©r#   r$   r&   r  )r'   s   "r(   r)   r)   k  sL   € ÷ <ñ <Ü�\‰\ð<Ü$)§L¡Lð<Ü;@¿<¹<ð<ÜV[ð<Üknð<ä
‡\�\ñ<r*   c                óœ  € \        W.4      w  rVVe%   \        VP                  V P                  4      4      p\        V 4      \        V4      rV P                  p\	        V P
                  P                  4      ;_uu_ 4        \        WV4      w  r‰p
\        V
4      p\        W‚W›RWW4      p\        V^,
          4       Fd  p\        WVR4      p\        P                  ! V) RV^,          ,          ,          4      p\        WV4      w  r‰p
\        V
4      p\        W�W›RWW4      pKf  	  RRR4       XP                  V4      #   + '       g   i     L!; i)a	  Estimate a homography by iteratively re-weighted DLT, with Gaussian weights of the transfer error.

``H = find_homography_dlt_iterated(points1, points2, weights)`` takes correspondences ``(B, N, 2)`` and initial
weights ``(B, N)`` and returns the homography ``(B, 3, 3)`` that maps ``points1`` to ``points2``, as
:func:`find_homography_dlt` does, after ``n_iter`` weighted DLT solves: each solve after the first re-weights the
correspondences by a Gaussian of their symmetric transfer error under the previous estimate, of standard
deviation ``soft_inl_th`` pixels. A correspondence whose symmetric error is ``e = 3 * soft_inl_th`` keeps a
weight of ``exp(-4.5)``, about 0.01, so the iterations suppress a few outliers when the first solve is close; for
many outliers use :class:`~kornia.geometry.ransac.RANSAC`, which refines its homography with this function under
``local_optimization="dlt"``.

Convention:
    - Direction, ``H[2, 2] = 1`` and autocast as :func:`find_homography_dlt`. Each solve after the first re-weights
      with the Gaussian kernel ``exp(-e**2 / (2 * soft_inl_th**2))`` of the symmetric transfer error ``e``
      (the root of the summed squared forward and backward transfer errors), so ``soft_inl_th`` is a
      standard deviation in pixels: a correspondence with ``e = soft_inl_th`` keeps weight ``exp(-1/2)``.

.. note::
    On MPS this needs torch 2.10 or later; see :ref:`MPS linear algebra <mps-linear-algebra>`.

Args:
    points1: A set of points in the first image with a tensor shape ``(B, N, 2)``.
    points2: A set of points in the second image with a tensor shape ``(B, N, 2)``.
    weights: Tensor containing the weights per point correspondence with a shape of ``(B, N)``.
      Used for the first iteration of the IRWLS.
    soft_inl_th: standard deviation, in pixels, of the Gaussian re-weighting kernel given above.
    n_iter: number of solves, including the initial one.

Returns:
    the computed homography matrix with shape ``(B, 3, 3)``, NaN for a batch element as in
    :func:`find_homography_dlt`.

See Also:
    - :func:`find_homography_dlt`: a single weighted solve.
    - :func:`find_homography_lines_dlt_iterated`: the same re-weighting for line segment correspondences.
    - :func:`symmetric_transfer_error`: the error the weights are computed from.

Nrh  Tç       @)r
   r   rx   rU   r	   rT   rÇ   rB  rD  rC  r*  ri   r#   Úexp)rá   rÓ   r?  r™  rš  rT   rU   r„   rë   rE  rF  r}  r   r`   Úsquared_errorsÚweights_news   &&&&&           r(   Úfind_homography_dlt_iteratedr¡  k  s  € ôR *¨7Ð*<Ó=�M€FàÒÜ# G§J¡J¨w¯}©}Ó$=Ó>ˆä(¨Ó1Ô3DÀWÓ3MˆWØ�=‰=€Dä	˜GŸN™N×/Ñ/×	0Õ	0ä$:¸7ÈWÓ$UÑ!ˆ�zÜ/°
Ó;ˆÜ5°aÀ*Ð^bÐdjÓqˆÜ�v •zÖ"ˆAÜ+CÀGÐVWÐY]Ó+^ˆNÜ(-¯	ª	°>°/ÀSÈKÐYZÍNÕE[Õ2\Ó(]ˆKÜ(>¸wÐQ\Ó(]Ñ%ˆA˜:Ü3°JÓ?ˆNÜ+¨A¸JÐX\Ð^dÓkŠAñ #÷ 
1ð �4‰4�‹;Ð÷ 
1×	0ús   Á?B#D;Ä;E	c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# rà   rÌ   )r'   s   "r(   r)   r)   ª  s0   € ÷ 90ñ 90¬E¯L©Lð 90Ä5Ç<Á<ð 90ÔTY×T`ÑT`ñ 90r*   c                óÚ  € V P                   VP                   8w  db   \        R\        V P                   4       R\        VP                   4       R2\        V P                   4      \        VP                   4      R7      hR R lpV! V 4      w  r4pV! V4      w  rgpR R lp	\        P                  ! V	! W4V4      4      p
\        P                  ! V	! WgV4      4      pW«8H  P                  ^R	7      # )
a  Test whether four correspondences keep their orientation across two views.

``valid = sample_is_valid_for_homography(points1, points2)`` takes minimal samples ``(B, 4, 2)`` of the first and
the second image, or ``(B, N, 2)`` of which the first four points are read, and returns a ``(B,)`` bool mask that
is True where each of the four triples of points has the same orientation in both images: the oriented
constraint of :cite:`Marquez-Neila2015`, analogous to OpenCV's USAC degeneracy test
(https://github.com/opencv/opencv/blob/4.x/modules/calib3d/src/usac/degeneracy.cpp#L88).
:class:`~kornia.geometry.ransac.RANSAC` uses it to discard minimal samples for ``"homography"`` before fitting
them.

Convention:
    - It checks only that the four triples of the first four points keep their orientation across the two
      views, so a mirror-image sample is rejected. A triple that is collinear in both views, for instance
      through a repeated point, counts as kept, so collinearity alone does not reject a sample.

Args:
    points1: A set of points in the first image with a tensor shape ``(B, N, 2)``; only the first four
      points are used.
    points2: A set of points in the second image with a tensor shape ``(B, N, 2)``; only the first four
      points are used.

Returns:
    Mask with the minimal sample is good for homography estimation ``(B,)``.

See Also:
    - :func:`find_homography_dlt`: the fit of a sample that passes.
    - :class:`~kornia.geometry.ransac.RANSAC`: the estimator that draws the samples this tests.

rO  rP  rQ  rR  c                ó¬   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  \         P                  3,          /# )r   rÃ   r!   rÅ   )r'   s   "r(   r)   Ú4sample_is_valid_for_homography.<locals>.__annotate__Ñ  s:   € ÷ tñ tœŸ™ð t¬%´·±¼e¿l¹lÌEÏLÉLÐ0XÕ*Yñ tr*   c                 óà   € V R,          V R,          V R,          V R,          3w  rr4\         P                  ! WW.^4      \         P                  ! W"W3.^4      \         P                  ! W4WD.^4      3# )r4   rð   rñ   rï   )r4   rs   )r#   rÙ   )rÃ   Úp0rÒ   Úp2Úp3s   &    r(   Ú_triplesÚ0sample_is_valid_for_homography.<locals>._triplesÑ  sg   € Ø � v¨d¥|°V¸Dµ\À6È$Å<ÐO‰ˆ�Ü�{Š{˜B BÐ+¨QÓ/´·²¸bÀbÐ=MÈqÓ1QÔSX×S^ÒS^Ð`bÐhjÐ_oÐqrÓSsÐsÐsr*   c                ó˜   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  /# )r   r–   r˜   r—   r!   rÌ   )r'   s   "r(   r)   r¥  Ú  s>   € ÷ Añ A”5—<‘<ð A¤E§L¡Lð A´U·\±\ð AÄeÇlÁlñ Ar*   c                 óˆ   € W,
          pW ,
          pVR,          VR,          ,          VR,          VR,          ,          ,
          # ).r0   r2   © )r–   r˜   r—   ÚabÚacs   &&&  r(   Ú_orientÚ/sample_is_valid_for_homography.<locals>._orientÚ  s5   € Ø�UˆØ�UˆØ�&�z˜B˜v�JÕ&¨¨F­°b¸µjÕ)@Õ@Ð@r*   r¥   )r7   r   rX  r#   Úsignrz   )rá   rÓ   rª  Úp1_iÚp1_jÚp1_kÚp2_iÚp2_jÚp2_kr±  Ú	left_signÚ
right_signs   &&          r(   Úsample_is_valid_for_homographyr¼  ª  sÖ   € ð< ‡}�}˜Ÿ™Ô%ÜØ@ÄÀgÇmÁmÓATÐ@UÐUZÔ[_Ð`g×`mÑ`mÓ[nÐZoÐopÐqÜ˜gŸm™mÓ,Ü §¡Ó.ô
ð 	
õtñ   Ó(Ñ€D�Ù Ó(Ñ€D�õAô
 —
’
™7 4¨tÓ4Ó5€IÜ—’™G D°Ó5Ó6€Jð Ñ#×(Ñ(¨QÐ(Ó/Ð/r*   c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\         P                  /# )r   rŸ   r    r?  r!   )r#   r$   r   )r'   s   "r(   r)   r)   æ  sG   € ÷ x:ñ x:Ü	�‰ðx:Ü!ŸL™Lðx:Ü3;¼E¿L¹LÕ3Iðx:ä
‡\�\ñx:r*   c                ó
  € \        V P                  4      ^8X  d
   V R,          p \        VP                  4      ^8X  d
   VR,          p\        V . RO4       \        V. RO4       V P                  R,          w  r4V^8  d   \        RV RV P                   24      h\	        W.4      w  rVVe   \        VP                  V4      4      p\        V 4      \        V4      rV P                  V^V,          ^4      pVP                  V^V,          ^4      pVez   VP                  V P                  R,          8w  dX   \        R\        V P                  R,          4       R\        VP                  4       R	2\        VP                  4      RR.R
7      h\        V P                  P                  4      ;_uu_ 4        Ve   VP                  ^^R7      MRp	\        WyR7      w  r«\        W‰R7      w  rÍV
P                  W4^^4      pVP                  W4^^4      pVR,          VR,          ppVR,          VR,          pp\        P                  ! VR^R7      w  pp\        P                  ! VR^R7      w  pp\        P                  ! VR^R7      w  pp\        P                  ! VR^R7      w  ppVV,
          pVV,
          pVV,          VV,          ,
          pRp\        P                   ! VV,          VV,          VVV,          VV,          VVV,          VV,          V.	RR7      p \        P                   ! VV,          VV,          VVV,          VV,          VVV,          VV,          V.	RR7      p!\        P                   ! V V!3RR7      P                  V^V,          V P                  R,          4      pVf   VP#                  RR4      V,          pMÕ\        VP                  4      ^8X  d#   VP                  V P                  R,          8X  gX   \        R\        V P                  R,          4       R\        VP                  4       R	2\        VP                  4      RR.R
7      hVP                  ^^R7      P%                  ^4      p"VP#                  RR4      V",          V,          p\'        V4      P)                  R^^4      p#\+        V4      V#V,          ,          p#\-        V#V4      P                  V4      uuRRR4       #   + '       g   i     R# ; i)aG
  Estimate a homography from four or more line segment correspondences by the DLT.

``H = find_homography_lines_dlt(ls1, ls2)`` takes segment correspondences ``(B, N, 2, 2)``, ``N >= 4``, each a
``[start, end]`` pair of ``(x, y)`` points, and returns the homography ``(B, 3, 3)`` that maps image-1 points to
image-2 points, scaled to ``H[2, 2] = 1`` unless that entry is numerically zero, from the constraint that both
endpoints of each image-1 segment map onto the line through the matching image-2 segment (:cite:`homolines2001`).
The endpoints need not be point correspondences, so segments detected with different extents still constrain
``H``. For point correspondences, use :func:`find_homography_dlt`; with outliers,
:class:`~kornia.geometry.ransac.RANSAC` with ``model_type="homography_from_linesegments"``.

Convention:
    - ``H`` maps image-1 points to image-2 points, as in :func:`find_homography_dlt`. ``weights`` has one entry
      per segment.
    - Each segment gives two constraints on the eight degrees of freedom of ``H``, so at least four segments
      are needed, as :func:`find_homography_dlt` needs four points.
    - A caller's autocast region does not change the fit.

Args:
    ls1: A set of line segments in the first image with a tensor shape ``(B, N, 2, 2)``, or
      ``(N, 2, 2)``, which is treated as :math:`B = 1`. ``N`` must be at least 4.
    ls2: A set of line segments in the second image with a tensor shape ``(B, N, 2, 2)``, or
      ``(N, 2, 2)``, which is treated as :math:`B = 1`.
    weights: Tensor containing the weights per segment with a shape of ``(B, N)``.
      Zero-weight segments are excluded from Hartley normalization.

Returns:
    the computed homography matrix with shape ``(B, 3, 3)``. A batch element whose weighted DLT system is
    not finite, because a weight or an endpoint is not finite (zero-weight segments included) or an entry
    overflows, is NaN on every device; the other elements are unaffected. If the SVD fails to converge on a
    finite system, the whole batch is NaN and a ``RuntimeWarning`` is issued.

Raises:
    ShapeError: if fewer than four segments are given, as in :func:`find_homography_dlt`.

See Also:
    - :func:`find_homography_dlt`: a homography from point correspondences.
    - :func:`find_homography_lines_dlt_iterated`: the same fit re-weighted by the line distance over a few
      solves.
    - :func:`line_segment_transfer_error_one_way`: the residual of segments under the result.
    - :class:`~kornia.geometry.ransac.RANSAC`: a homography from segments with outliers, with
      ``model_type="homography_from_linesegments"``.

Nr-   r¨   r¢   z>find_homography_lines_dlt needs at least 4 line segments, got z: rU  rV  rQ  rR  r¥   rW  r£   r  r§   r'  )r4   r4   r3   r/   rt   )r‚  r7   r   r   r
   r   rx   rê   rX  r	   rT   rÇ   rƒ  r   r#   rª   rØ   rÈ   r„  r{  r]   rD  r   )$rŸ   r    r?  ÚBSr¨   r`   rU   rá   rÓ   Úendpoint_weightsrZ  rE  r[  rF  Úsegments1_normÚsegments2_normÚlst1Úle1Úlst2Úle2Úxs1Úys1Úxs2Úys2Úxe1Úye1Úxe2Úye2rë   r-   ÚCr    rÜ   rÝ   rŒ  r   s$   &&&                                 r(   Úfind_homography_lines_dltrÐ  æ  s8  € ô\ ˆ3�9‰9ƒ~˜ÔØ�$�iˆÜ
ˆ3�9‰9ƒ~˜ÔØ�$�iˆÜ�sÒ0Ô1Ü�sÒ0Ô1Ø�I‰I�b�M�E€Bð 	ˆ1„uÜÐYÐZ[ÐY\Ð\^Ð_b×_hÑ_hÐ^iÐjÓkÐkä$ c ZÓ0�H€AàÒÜ# G§J¡J¨uÓ$5Ó6ˆä  Ó%Ô'8¸Ó'=ˆà�k‰k˜"˜a !�e QÓ'€GØ�k‰k˜"˜a !�e QÓ'€GàÒ˜wŸ}™}°·	±	¸"µÔ=ÜØ/´°S·Y±Y¸rµ]Ó0CÐ/DÀFÌ4ÐPW×P]ÑP]ÓK^ÐJ_Ð_`ÐaÜ˜gŸm™mÓ,Ø ˜:ô
ð 	
ô 
˜CŸJ™JŸO™O×	,Õ	,ØBIÒBU˜7×4Ñ4°Q¸AÐ4Ô>Ð[_ÐÜ#3°GÔ#VÑ ˆÜ#3°GÔ#VÑ ˆà%×-Ñ-¨b°Q¸Ó:ˆØ%×-Ñ-¨b°Q¸Ó:ˆØ" 7Õ+¨^¸GÕ-DˆcˆØ" 7Õ+¨^¸GÕ-Dˆcˆä—;’;˜t¨°AÔ6‰ˆˆSÜ—;’;˜t¨°AÔ6‰ˆˆSÜ—;’;˜s¨°1Ô5‰ˆˆSÜ—;’;˜s¨°1Ô5‰ˆˆSà�#�IˆØ�#�IˆØ�#�I˜˜c�	Õ!ˆàˆô �YŠY˜˜C�  S¥¨!¨Q°­W°a¸#µg¸qÀ!ÀcÅ'È1ÈsÍ7ÐTUÐVÐ\^Ô_ˆÜ�YŠY˜˜C�  S¥¨!¨Q°­W°a¸#µg¸qÀ!ÀcÅ'È1ÈsÍ7ÐTUÐVÐ\^Ô_ˆä�IŠI�r˜2�h BÔ'×/Ñ/°°A¸µE¸2¿8¹8ÀB½<ÓHˆàŠ?à—‘˜B Ó# aÕ'‰Aô ˜Ÿ™Ó'¨1Ô,°7·=±=ÀCÇIÁIÈbÅMÔ3QÜ Ø7¼¸S¿Y¹YÀr½]Ó8KÐ7LÈFÔSWÐX_×XeÑXeÓSfÐRgÐghÐiÜ!% g§m¡mÓ!4Ø$'¨ :ôð ð ×.Ñ.¨q°aÐ.Ó8×BÑBÀ1ÓEˆFØ—‘˜R Ó$ vÕ-°Õ2ˆAä˜QÓ×$Ñ$ R¨¨AÓ.ˆÜ" :Ó.°!°jµ.ÕAˆÜ'¨¨3Ó/×2Ñ2°5Ó9÷[ 
-×	,×	,Ó	,ús   Æ3L6S4Ó4T	c                ó°   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\         P                  /# )r   rŸ   r    r?  r™  rš  r!   r›  )r'   s   "r(   r)   r)   a  sL   € ÷ :ñ :Ü	�‰ð:Ü!ŸL™Lð:Ü38·<±<ð:ÜNSð:Ücfð:ä
‡\�\ñ:r*   c           	     ót  € \        V P                  4      ^8X  d
   V R,          p \        VP                  4      ^8X  d
   VR,          pV P                  pVe   VP                  V4      p\	        V 4      \	        V4      r\        V P                  P                  4      ;_uu_ 4        \        WV4      p\        V^,
          4       FG  p\        WV4      p\        P                  ! V) RV^,          ,          ,          4      p	\        WV	4      pKI  	  RRR4       XP                  V4      #   + '       g   i     L!; i)a~  Estimate a homography from line segments by iteratively re-weighted DLT.

``H = find_homography_lines_dlt_iterated(ls1, ls2, weights)`` takes segment correspondences ``(B, N, 2, 2)``,
``N >= 4``, and initial weights ``(B, N)`` and returns the homography ``(B, 3, 3)`` that maps image-1 points to
image-2 points, as :func:`find_homography_lines_dlt` does, after ``n_iter`` weighted solves: each solve after the
first re-weights the segments by a Gaussian, of standard deviation ``soft_inl_th`` pixels, of the mean distance
of their mapped endpoints from the matched lines under the previous estimate. For point correspondences, use
:func:`find_homography_dlt_iterated`.

Convention:
    - As :func:`find_homography_dlt_iterated`, with :func:`find_homography_lines_dlt` as the solver and, as
      ``e`` in the Gaussian kernel, the perpendicular distance in pixels of the mapped image-1 endpoints from
      the image-2 line. A zero-length image-2 segment gets weight zero.

Args:
    ls1: A set of line segments in the first image with a tensor shape ``(B, N, 2, 2)``, or
      ``(N, 2, 2)``, which is treated as :math:`B = 1`, as in :func:`find_homography_lines_dlt`.
    ls2: A set of line segments in the second image with a tensor shape ``(B, N, 2, 2)``, or
      ``(N, 2, 2)``, which is treated as :math:`B = 1`.
    weights: Tensor containing the weights per segment with a shape of ``(B, N)``.
      Used for the first iteration of the IRWLS.
    soft_inl_th: standard deviation, in pixels, of the Gaussian re-weighting kernel of
      :func:`find_homography_dlt_iterated`.
    n_iter: number of solves, including the initial one.

Returns:
    the computed homography matrix with shape ``(B, 3, 3)``. A batch element is NaN when one of its
    solves is, as in :func:`find_homography_lines_dlt`.

Raises:
    ShapeError: if fewer than four segments are given, as in :func:`find_homography_lines_dlt`.

See Also:
    - :func:`find_homography_lines_dlt`: a single weighted solve.
    - :func:`find_homography_dlt_iterated`: the same re-weighting for point correspondences.
    - :func:`line_segment_transfer_error_one_way`: the distance the weights are computed from.

Nr�  )r‚  r7   rU   rx   r   r	   rT   rÇ   rÐ  r*  rÐ   r#   rž  )
rŸ   r    r?  r™  rš  rU   r   r`   Úsquared_distancesr   s
   &&&&&     r(   Ú"find_homography_lines_dlt_iteratedrÔ  a  sò   € ôT ˆ3�9‰9ƒ~˜ÔØ�$�iˆÜ
ˆ3�9‰9ƒ~˜ÔØ�$�iˆà�I‰I€EØÒØ—*‘*˜UÓ#ˆÜ  Ó%Ô'8¸Ó'=ˆä	˜CŸJ™JŸO™O×	,Õ	,Ü3°C¸gÓFˆÜ�v •zÖ"ˆAÜ.TÐUXÐ_`Ó.aÐÜ(-¯	ª	Ð3DÐ2DÈÈ{Ð\]Í~ÕH^Õ2_Ó(`ˆKÜ)¨#°KÓ@ŠAñ #÷ 
-ð �4‰4�‹;Ð÷ 
-×	,ús   Â$A*D'Ä'D7	)	rG  r¡  rÐ  rÔ  rÁ   rP   r¼  r�   ri   )Tr  )T)F)Nrh  )N)g      @é   )g      @rÕ  )@Ú__doc__r€   ru  Útypingr   r   r   r#   Úkornia.core.checkr   r   Úkornia.core.exceptionsr   Úkornia.core.utilsr   r	   r
   r   r   r   r   Úkornia.geometry.conversionsr   r   Úkornia.geometry.epipolarr   r   Ú!kornia.geometry.epipolar._metricsr   Ú$kornia.geometry.epipolar.fundamentalr   Úkornia.geometry.linalgr   r   r   Ú#kornia.geometry.solvers.homogeneousr   Ú__all__r$   ÚTupleTensorrP   ri   r�   rÁ   r¯   rÐ   rÞ   rä   rì   rö   r8   r  r  r=  rG  rD  rB  rp  r{  rC  r¡  r¼  rÐ  rÔ  r®  r*   r(   Ú<module>rã     sÿ   ðñ$ó: Û ß )Ñ )ã ç >Ý -÷÷ ñ ÷ gß OÝ <Ý =ß FÑ FÝ >ò
€ð �E—L‘L %§,¡,Ð.Õ/€÷Z4÷z?8÷DX÷vF5õRAõ _õ
9õfõ
Yõ$õ5õ.õ&YõI÷XFõR`÷%õ@Rõ:Sõ0_,÷D<õ~90÷xx:÷v:ñ :r*   