+
    åûj>>  ã                  ó¤   € R t ^ RIHt ^ RIHt ^ RIt^ RIHu Ht	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^R	IHtHt RR
 R lltR R ltR# )zURemove OpenCV's Brown-Conrady lens distortion from pixel coordinates and from images.)Úannotations)ÚOptionalN)ÚKORNIA_CHECK_SHAPE©Ú_at_least_float32)Úcreate_meshgrid)Útransform_points)Úremap)Údistort_pointsÚtilt_projectionc               ó0   € V ^8„  d   QhRRRRRRRRRRR	R/# )
é   Úpointsútorch.TensorÚKÚdistÚnew_KzOptional[torch.Tensor]Ú	num_itersÚintÚreturn© )Úformats   "ÚaC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\calibration\undistort.pyÚ__annotate__r   %   sL   € ÷ gVñ gVØðgVØ)ðgVØ1=ðgVØF\ðgVØpsðgVàñgVó    c                ó\
  € \        V . RO4       \        V. R	O4       V P                  4       ^8  d2   V P                  R
,          ^8w  d   \        RV P                   R24      hVf   TpM\        V. R	O4       VP                  R
,          R9  d    \        RVP                  R
,           24      h\        P
                  ! \        P
                  ! V P                  VP                  4      \        P
                  ! VP                  VP                  4      4      pR WW23 4       w  rr2VP                  R
,          ^8H  pVP                  R
,          ^8  d2   \        P                  ! V^ ^VP                  R
,          ,
          .4      pVR,          pVR,          pVR,          p	VR,          p
V R,          V,
          V	,          pV R,          V,
          V
,          pV'       dÛ   \        VR,          VR,          R4      p\        P                  ! W¼.R
R7      p\        \        P                  ! VR,          VR,          4      ^ ,          P                  RR 4      pVP                  V^^.,           4      pVP                  V\        VP                  RR 4      ,           4      p\        WÞ4      P                  R
4      w  r¼Y¼pp\!        V4       EFÎ  pW»,          WÌ,          ,           p^VR,          V,          ,           VR,          V,          V,          ,           VR,          V^,          ,          ,           ^VR,          V,          ,           VR,          V,          V,          ,           VR,          V^,          ,          ,           ,          p^VR,          ,          V,          V,          VR,          V^V,          V,          ,           ,          ,           VR,          V,          ,           VR,          V,          V,          ,           pVR,          V^V,          V,          ,           ,          ^VR,          ,          V,          V,          ,           VR ,          V,          ,           VR!,          V,          V,          ,           pVV,
          V,          pVV,
          V,          pEKÑ  	  VR,          pVR,          pVR,          pVR,          pVV,          V,           pVV,          V,           p\        P                  ! W¼.R
4      pV\        P"                  \        P$                  39   d   VP'                  V4      # T# )"ax  Remove Brown-Conrady lens distortion from pixel coordinates by fixed-point iteration.

``points = undistort_points(distorted, K, dist)`` takes measured pixels ``(*, N, 2)``, the intrinsics
``(*, 3, 3)`` and OpenCV's coefficient vector ``(*, n)``, ``n`` one of 4, 5, 8, 12 or 14, and returns the
ideal pinhole pixels ``(*, N, 2)`` after ``num_iters`` fixed-point steps; within the convergence region, with
the default 5 steps, the result matches ``cv2.undistortPoints(points, K, dist, P=P)`` with
``P = K if new_K is None else new_K`` and no skew in ``P``: OpenCV applies ``P[0, 1]``, which this function
ignores, and without ``P`` it returns normalized coordinates. For normalized
coordinates, as :func:`~kornia.geometry.epipolar.find_essential` takes, pass the result to
:func:`~kornia.geometry.conversions.normalize_points_with_intrinsics`; for a whole image, use
:func:`~kornia.geometry.calibration.undistort_image`.

Radial :math:`(k_1, k_2, k_3, k_4, k_5, k_6)`,
tangential :math:`(p_1, p_2)`, thin prism :math:`(s_1, s_2, s_3, s_4)`, and tilt :math:`(\tau_x, \tau_y)`
distortion models are considered in this function.

Convention:
    - ``points`` are **pixel** coordinates in ``(u, v)`` order and so is the result (integer pixel centres;
      see :class:`~kornia.geometry.camera.pinhole.PinholeCamera`).
    - ``dist`` follows the layout of :func:`~kornia.geometry.calibration.distort_points`, the forward map
      this function inverts; ``K`` maps the incoming pixel onto the normalized plane and ``new_K`` maps the
      undistorted point back to pixels.
    - the inverse is a fixed-point iteration of ``num_iters`` steps, so the round trip through
      :func:`~kornia.geometry.calibration.distort_points` closes only to the accuracy the iteration reaches;
      within its convergence region more steps improve it down to the dtype's rounding.
    - matching leading dimensions of ``points``, ``K`` and ``dist`` are preserved, and the leading dimensions
      broadcast as in :func:`~kornia.geometry.calibration.distort_points`, the sensor-tilt step of 14
      coefficients included.
    - the skew entries ``K[0, 1]`` and ``new_K[0, 1]`` are ignored, as in
      :func:`~kornia.geometry.conversions.normalize_points_with_intrinsics`.
    - float16 and bfloat16 inputs are iterated in float32 and the result is returned in their dtype.

.. warning::
    The iteration has no convergence test and no valid-radius guard: outside the convergence region it can
    enter a two-point cycle, so the answer depends on the parity of ``num_iters``.
    `#4285 <https://github.com/kornia/kornia/issues/4285>`_.

Args:
    points: Input image points with shape ``(*, N, 2)``.
    K: Intrinsic camera matrix with shape ``(*, 3, 3)``.
    dist: Distortion coefficients
        :math:`(k_1,k_2,p_1,p_2[,k_3[,k_4,k_5,k_6[,s_1,s_2,s_3,s_4[,\tau_x,\tau_y]]]])`. This is
        a vector with 4, 5, 8, 12 or 14 elements with shape ``(*, n)``.
    new_K: Intrinsic camera matrix used to map the undistorted normalized point back to pixels, while ``K``
        is the one that maps the incoming distorted ``points`` from pixels onto the normalized
        :math:`z = 1` plane -- the mirror image of the two roles in
        :func:`~kornia.geometry.calibration.distort_points`. By default it is the same as ``K``, in which
        case both steps use the same camera; a different matrix rescales and shifts the **result**.
        Shape: ``(*, 3, 3)``. Default: None.
    num_iters: Number of undistortion iterations. Default: 5.

Returns:
    Undistorted 2D points with shape ``(*, N, 2)``.

See Also:
    - :func:`~kornia.geometry.calibration.distort_points`: the forward map, in closed form, with ``K`` and
      ``new_K`` in mirrored roles.
    - :func:`~kornia.geometry.calibration.undistort_image`: undistorts every pixel of an image instead of a
      point list.
    - :func:`~kornia.geometry.calibration.tilt_projection`: the inverse sensor-tilt matrix applied first with
      14 coefficients.
    - :func:`~kornia.geometry.camera.undistort_points_kannala_brandt`: the fisheye inverse, from pixels to
      normalized points.
    - :func:`~kornia.geometry.camera.undistort_points_affine`: the intrinsics alone, from pixels to normalized
      points, in closed form.
    - :class:`~kornia.sensors.camera.distortion_model.BrownConradyTransform`: the same inverse on ``Vector2``
      pixels, to normalized points.

Example:
    >>> _ = torch.manual_seed(0)
    >>> x = torch.rand(1, 4, 2)
    >>> K = torch.eye(3)[None]
    >>> dist = torch.rand(1, 4)
    >>> undistort_points(x, K, dist)
    tensor([[[-0.1513, -0.1165],
             [ 0.0711,  0.1100],
             [-0.0697,  0.0228],
             [-0.1843, -0.1606]]])

zpoints shape is invalid. Got Ú.Nú/Invalid number of distortion coefficients. Got c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i)Nr   )Ú.0Úts   & r   Ú	<genexpr>Ú#undistort_points.<locals>.<genexpr>‹   s   é € ÐUÑ<T°qÔ/°×2Ð2Ó<Tùs   ‚T)Údim)Ú*ÚNÚ2)r$   Ú3r'   éÿÿÿÿ©é   é   é   é   é   ).ºé    é   Nr   ).ºr1   r   Nr   ).r/   r0   ).r2   r1   ©.r0   ©.r1   ).:r-   é   N).:r5   r.   N).ºNr1   Nr6   éþÿÿÿ).:r+   é   N).:r8   é   N).:r9   r,   N).r/   ).r2   ).:r*   r+   N).:r   é   N).:r:   r*   N).:r,   é	   N).:r;   é
   N).:r<   é   N).:r=   r-   N)r   r#   ÚshapeÚ
ValueErrorÚtorchÚpromote_typesÚdtypeÚFÚpadr   ÚstackÚlistÚbroadcast_tensorsÚexpandr   ÚunbindÚrangeÚfloat16Úbfloat16Úto)r   r   r   r   r   Ú	out_dtypeÚhas_tiltÚcxÚcyÚfxÚfyÚxÚyÚinv_tiltÚxyÚbatch_shapeÚx0Úy0Ú_Úr2Úinv_rad_polyÚdeltaXÚdeltaYÚnew_cxÚnew_cyÚnew_fxÚnew_fyÚouts   &&&&&                       r   Úundistort_pointsre   %   s=  € ôf �všÔ/Ü�qš/Ô*à‡z�zƒ|�aÔ˜FŸL™L¨Õ,°Ô1ÜÐ8¸¿¹¸ÀaÐHÓIÐIà‚}Ø‰ä˜5¢/Ô2à‡z�z�"…~Ð.Ô.ÜÐJÈ4Ï:É:ÐVXÍ>ÐJZÐ[Ó\Ð\ô ×#Ò#Ü×Ò˜FŸL™L¨!¯'©'Ó2´E×4GÒ4GÈÏ
É
ÐTY×T_ÑT_Ó4`ó€Iñ V¸VÈÑ<TÓUÑ€Fˆuà�z‰z˜"�~ Ñ#€Hà‡z�z�"…~˜ÔÜ�uŠu�T˜A˜r D§J¡J¨r¥NÕ2Ð3Ó4ˆð ˜•~€BØ˜•~€BØ˜•~€BØ˜•~€Bð ˜f•~¨Õ*¨bÕ0€AØ˜f•~¨Õ*¨bÕ0€A÷ Ü" 4¨
Õ#3°T¸*Õ5EÀtÓLˆÜ�[Š[˜!˜ RÔ(ˆô œ5×2Ò2°2°kµ?ÀHÈ[ÕDYÓZÐ[\Õ]×cÑcÐdgÐegÐhÓiˆØ—?‘? ;°!°Q°Õ#7Ó8ˆØ�Y‰Y�{¤T¨"¯(©(°2°3¨-Ó%8Õ8Ó9ˆô   Ó-×4Ñ4°RÓ8‰ˆð ˆ€BÜ�9×ˆØ�U�Q•U�]ˆà˜D �N¨RÕ/Õ/°$°xµ.À2Õ2EÈÕ2JÕJÈTÐRZÍ^Ð^`ÐbcÕ^cÕMcÕcØ��X• Õ#Õ# d¨8¥n°rÕ&9¸BÕ&>Õ>ÀÀhÅÐRTÐVWÕRWÕAWÕWõ
ˆð ��X•Õ Õ" QÕ&Ø�8�n  Q¨¥U¨Q¥Y¥Õ/õ0à�8�n˜rÕ!õ"ð �9�o Õ" RÕ'õ(ð 	ð ��N˜b 1 q¥5¨1¥9�nÕ-Ø�$�x•.Õ  1Õ$ qÕ(õ)à�:Õ Õ#õ$ð �:Õ Õ# bÕ(õ)ð 	ð �&�[˜LÕ(ˆØ�&�[˜LÕ(‹ñ) ð. ! Õ-€FØ  Õ-€FØ  Õ-€FØ  Õ-€FØ��
�VÕ€AØ��
�VÕ€AÜ
�+Š+�q�f˜bÓ
!€Cà )¬e¯m©m¼U¿^¹^Ð-LÔ Lˆ3�6‰6�)ÓÐUÐRUÐUr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úimager   r   r   r   r   )r   s   "r   r   r   Ð   s/   € ÷ _.ñ _.˜<ð _.¨Lð _.Àð _.ÐQ]ñ _.r   c           
     óö  € \        V P                  4      ^8  d   \        RV P                   R24      hVP                  RR R8w  d   \        RVP                   R24      hVP                  R,          R9  d!   \        RVP                  R,           R24      hV P                  4       '       g   \        RV P                   R24      hV P                  RR VP                  RR 8w  g"   V P                  RR VP                  RR 8w  d�   \        V P                  RR R8H  VP                  RR R8H  VP                  RR R8H  34      '       g=   \        RV P                  RR  RVP                  RR  RVP                  RR  R24      hV P                  RR w  r4pV P                  4       W4,          V,          ,          pV P                  \        P                  \        P                  39   d   \        P                  MV P                  pWpP                  8w  d"   VP                  V4      VP                  V4      r!\        WER	V P                  V4      pVP                  R^4      p	\        W‘V4      p
V
R,          P                  WdV4      pV
R,          P                  WdV4      p\!        V P                  WcWE4      P                  V4      W¼R
R7      pVP                  V P                  4      P#                  V 4      # )aŠ  Undistort an image with OpenCV's Brown-Conrady coefficients, keeping its camera matrix K.

``out = undistort_image(image, K, dist)`` takes images ``(*, C, H, W)``, the intrinsics ``(*, 3, 3)`` and
OpenCV's coefficient vector ``(*, n)``, ``n`` one of 4, 5, 8, 12 or 14, and returns the image a camera with the
same ``K`` and no distortion would take, ``(*, C, H, W)``: each output pixel samples the input bilinearly at its
:func:`~kornia.geometry.calibration.distort_points` position, with zeros outside the input. There is no
``new_K``, so the result keeps the input's size and ``K``, as ``cv2.undistort`` does by default. For point
coordinates, use :func:`~kornia.geometry.calibration.undistort_points`.

Radial :math:`(k_1, k_2, k_3, k_4, k_5, k_6)`,
tangential :math:`(p_1, p_2)`, thin prism :math:`(s_1, s_2, s_3, s_4)`, and tilt :math:`(\tau_x, \tau_y)`
distortion models are considered in this function.

Convention:
    - the leading dimensions of ``image`` (in front of ``C, H, W``), ``K`` (in front of :math:`3 \times 3`)
      and ``dist`` (in front of its ``n`` coefficients) must match exactly, so an unbatched ``(C, H, W)``
      image takes a ``(3, 3)`` ``K`` and an ``(n,)`` ``dist``; the one exception is the legacy unbatched
      call, a ``(1, C, H, W)`` image with a ``(3, 3)`` ``K`` and an ``(n,)`` ``dist``.
    - an image that is not floating point raises :class:`ValueError`.
    - the sampling map applies :func:`~kornia.geometry.calibration.distort_points` to the integer pixel
      centres (see :class:`~kornia.geometry.camera.pinhole.PinholeCamera`) and is resampled bilinearly with
      a fixed ``align_corners=True``, so all-zero coefficients return the input only to rounding.
    - a float16 or bfloat16 image builds the map, distorts it and samples in float32, with ``K`` and ``dist``
      cast to float32, and returns the image dtype; in half precision the pixel coordinates themselves round to
      half pixels (float16, from 512) or whole pixels (bfloat16, from 128).

Args:
    image: Input image with shape ``(*, C, H, W)``.
    K: Intrinsic camera matrix with shape ``(*, 3, 3)``.
    dist: Distortion coefficients
        :math:`(k_1,k_2,p_1,p_2[,k_3[,k_4,k_5,k_6[,s_1,s_2,s_3,s_4[,\tau_x,\tau_y]]]])`. This is
        a vector with 4, 5, 8, 12 or 14 elements with shape ``(*, n)``.

Returns:
    Undistorted image with shape ``(*, C, H, W)``.

See Also:
    - :func:`~kornia.geometry.calibration.undistort_points`: undistorts a list of pixel coordinates instead of
      an image.
    - :func:`~kornia.geometry.calibration.distort_points`: the map whose positions the image is sampled at.
    - :func:`~kornia.geometry.transform.remap`: the sampling step, to resample with other maps or options.

Example:
    >>> img = torch.rand(1, 3, 5, 5)
    >>> K = torch.eye(3)[None]
    >>> dist_coeff = torch.rand(1, 4)
    >>> out = undistort_image(img, K, dist_coeff)
    >>> out.shape
    torch.Size([1, 3, 5, 5])

zImage shape is invalid. Got: r   NzK matrix shape is invalid. Got r   z:Invalid input image data type. Input should be float. Got zAInput shape is invalid. Input batch dimensions should match. Got z, FT)Úalign_cornersr7   )r:   r:   r(   r)   éýÿÿÿ)r1   r   r3   r4   )Úlenr>   r?   Úis_floating_pointrB   ÚallÚnumelr@   rK   rL   Úfloat32rM   r   ÚdeviceÚreshaper
   r	   Úview_as)rg   r   r   ÚchannelsÚrowsÚcolsÚBÚ
work_dtypeÚxy_gridÚptsÚptsdÚmapxÚmapyrd   s   &&&           r   Úundistort_imager}   Ð   sª  € ôh ˆ5�;‰;Ó˜!ÔÜÐ8¸¿¹¸ÀQÐGÓHÐHà‡w�wˆrˆs€|�vÔÜÐ:¸1¿7¹7¸)À1ÐEÓFÐFà‡z�z�"…~Ð.Ô.ÜÐJÈ4Ï:É:ÐVXÍ>ÐJZÐZ[Ð\Ó]Ð]à×"Ñ"×$Ò$ÜÐUÐV[×VaÑVaÐUbÐbcÐdÓeÐeð 	�‰�C�RÐ˜AŸG™G C R˜LÔ(¨E¯K©K¸¸Ð,<ÀÇ
Á
È3ÈBÀÔ,OÔY\Ø	�‰�S�bÐ	˜TÑ	! 1§7¡7¨3¨B <°2Ñ#5°t·z±zÀ#À2°È"Ñ7LÐM÷Zò Zô ðØ—;‘;˜s Ð#Ð$ B q§w¡w¨s° | n°B°t·z±zÀ#À2°Ð6GÀqðJó
ð 	
ð
 !Ÿ;™; r sÐ+Ñ€H�DØ�‰‹˜(�/¨DÕ0Õ1€Að #(§+¡+´%·-±-ÄÇÁÐ1PÔ"P”—’ÐV[×VaÑVa€JØ—[‘[Ô Ø—$‘$�zÓ" D§G¡G¨JÓ$7ˆ4ô ,¨D¸¸u¿|¹|ÈZÓX€GØ
�/‰/˜"˜aÓ
 €Cô (¨°Ó5€DØ˜f�×-Ñ-¨a°tÓ<€DØ˜f�×-Ñ-¨a°tÓ<€Dô �—‘˜a¨4Ó6×9Ñ9¸*ÓEÀtÐaeÔ
f€Cà�6‰6�%—+‘+Ó×&Ñ& uÓ-Ð-r   )Nr+   )Ú__doc__Ú
__future__r   Útypingr   r@   Útorch.nn.functionalÚnnÚ
functionalrC   Úkornia.core.checkr   Úkornia.core.utilsr   Úkornia.geometry.gridr   Úkornia.geometry.linalgr   Úkornia.geometry.transformr	   Údistortr
   r   re   r}   r   r   r   Ú<module>rŠ      s:   ðñ$ \å "å ã ß Ð å 0Ý /Ý 0Ý 3Ý +ç 4÷gV÷V_.r   