+
    åûj)-  ã                  óŒ   € ^ RI Ht ^ RIt^ RIHtHt ^ RIt^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^RIHtHt RtR	.t ! R
 R	4      tR# )é    )ÚannotationsN)ÚClassVarÚUnion)ÚKORNIA_CHECKÚKORNIA_CHECK_SAME_DEVICESÚKORNIA_CHECK_SHAPE)Únumpy)Úonnxruntime)Údownload_onnx_from_urlÚnormalize_keypointsa�  Keypoints must lie inside the image: normalized by the image size they have to be in [-1, 1]. The keypoints are (x, y) pixel coordinates. The image size is (width, height) for the ``image_size`` of LightGlue and OnnxLightGlue, and (height, width) for the ``hw1`` / ``hw2`` of LightGlueMatcher; the wrong order, or keypoints detected on a differently sized image, put them out of range.ÚOnnxLightGluec                  ót   € ] tR t^)t$ RtRRRRRRRR	/tR
]R&   RR.tR]R&   RR R lltR R lt	R R lt
RtR# )r   a>	  Match the keypoints and descriptors of one image pair with an exported LightGlue ONNX model.

``matcher = OnnxLightGlue("disk", device="cpu")`` downloads an exported LightGlue :cite:`LightGlue2023` model,
or loads your own ONNX file, into an onnxruntime session, and ``out = matcher(data)`` takes the dicts of
:class:`LightGlue` for a batch of one: float32 ``keypoints`` ``(1, M, 2)`` in pixels and ``descriptors``
``(1, M, D)`` on that device, with ``image_size`` ``(1, 2)`` as ``(W, H)`` or an ``image``. It returns the
matched index pairs ``matches`` ``(S, 2)`` and their ``scores`` ``(S,)``. It needs ``onnxruntime`` and runs on
CPU or CUDA only. For batches, other devices or dtypes, scales, orientations or LAFs, or the full outputs of the
network, use :class:`LightGlue` instead.

If you have trained your own LightGlue model, see https://github.com/fabio-sim/LightGlue-ONNX
for how to export the model to ONNX and optimize it.

Convention:
    - See the Convention block on :class:`~kornia.feature.LightGlue`: the keypoints are normalised the same way,
      with ``image_size`` in the order ``(W, H)``, and the same range check applies. Unlike
      :class:`~kornia.feature.LightGlue`, it takes float32 inputs with a batch of one and no scales, orientations
      or LAFs, and it runs on CPU or CUDA only.
    - Known defect: the session and its inputs are bound to GPU 0 for every CUDA ``device``, so
      ``device="cuda:1"`` does not run on GPU 1 (`#6427 <https://github.com/kornia/kornia/issues/6427>`_).

Args:
    weights: Pretrained weights, or a path to your own exported ONNX model. Available pretrained weights
      are ``'disk'``, ``'superpoint'``, ``'disk_fp16'``, and ``'superpoint_fp16'``. `Note that FP16 requires CUDA.`
      Defaults to ``'disk_fp16'`` if ``device`` is CUDA, and ``'disk'`` if CPU.
    device: ``'cpu'`` or ``'cuda'`` to run inference on; another device type raises ``ValueError``. ``None``
      means ``'cpu'``, as in the other kornia feature constructors, not torch's current default device.

See Also:
    - :class:`LightGlue`: the PyTorch network, which also runs batches, on MPS, and in float16, bfloat16 or
      float64 (see its Convention block), and returns every output.
    - :class:`LightGlueMatcher`: LightGlue on descriptors and LAFs, returning scores and index pairs like the
      other kornia matchers.

Údiskz^https://github.com/fabio-sim/LightGlue-ONNX/releases/download/v1.0.0/disk_lightglue_fused.onnxÚ
superpointzdhttps://github.com/fabio-sim/LightGlue-ONNX/releases/download/v1.0.0/superpoint_lightglue_fused.onnxÚ	disk_fp16zchttps://github.com/fabio-sim/LightGlue-ONNX/releases/download/v1.0.0/disk_lightglue_fused_fp16.onnxÚsuperpoint_fp16zihttps://github.com/fabio-sim/LightGlue-ONNX/releases/download/v1.0.0/superpoint_lightglue_fused_fp16.onnxzClassVar[dict[str, str]]Ú
MODEL_URLSÚimage0Úimage1zClassVar[list[str]]Úrequired_data_keysNc               ó$   € V ^8„  d   QhRRRRRR/# )é   Úweightsz
str | NoneÚdevicezUnion[str, torch.device, None]ÚreturnÚNone© )Úformats   "ÚcC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\lightglue_onnx\lightglue.pyÚ__annotate__ÚOnnxLightGlue.__annotate__W   s(   € ÷ Kñ K 
ð KÐ;Yð KÐfjñ Kó    c                	ó¦  € \         P                  p\        \        P                  P                  R 4      RJR4       Vf   \        P                  ! R4      M\        P                  ! V4      pW n        VP                  R8X  d   R.pM$VP                  R8X  d   RR.pM\        RV 24      hVf   VP                  R8X  d   RMR	pWP                  9   db   R
V9   d   \        VP                  R8H  R4       V P                  V,          pVP                  R8X  d   VP                  RR4      p\        V4      p\         P                  ! WR7      V n        R# )r	   Nznumpy is not installed.ÚcpuÚCPUExecutionProviderÚcudaÚCUDAExecutionProviderzUnsupported device r   r   Úfp16zFP16 requires CUDA.z.onnxz	_cpu.onnx)Ú	providers)Ú_ortÚ__version__r   Ú	importlibÚutilÚ	find_specÚtorchr   ÚtypeÚ
ValueErrorr   Úreplacer   ÚInferenceSessionÚsession)Úselfr   r   Ú_r)   Úurls   &&&   r   Ú__init__ÚOnnxLightGlue.__init__W   s  € ô ×ÑˆÜ”Y—^‘^×-Ñ-¨gÓ6¸dÐBÐD]Ô^à(.ª”—’˜eÔ$¼E¿LºLÈÓ<PˆØŒà�;‰;˜%ÔØ/Ð0‰IØ�[‰[˜FÔ"Ø0Ð2HÐI‰IäÐ2°6°(Ð;Ó<Ð<àŠ?Ø%+§[¡[°FÔ%:‘kÀˆGà—o‘oÔ%Ø˜Ô Ü˜VŸ[™[¨FÑ2Ð4IÔJà—/‘/ 'Õ*ˆCØ�{‰{˜eÔ#Ø—k‘k '¨;Ó7�ä,¨SÓ1ˆGä×,Ò,¨WÔJˆŽr"   c               ó    € V ^8„  d   QhRRRR/# ©r   Údataz"dict[str, dict[str, torch.Tensor]]r   zdict[str, torch.Tensor]r   )r   s   "r   r    r!   w   s   € ÷ 	"ñ 	"Ð?ð 	"ÐD[ñ 	"r"   c                ó$   € V P                  V4      # )zÝRun the ONNX LightGlue matcher.

Args:
    data: Dictionary containing image features, keypoints, descriptors, and image sizes for matching.

Returns:
    Dictionary containing ONNX LightGlue matches and matching scores.
)Úforward)r5   r<   s   &&r   Ú__call__ÚOnnxLightGlue.__call__w   s   € ð �|‰|˜DÓ!Ð!r"   c               ó    € V ^8„  d   QhRRRR/# r;   r   )r   s   "r   r    r!   ‚   s    € ÷ nñ nÐ>ð nÐCZñ nr"   c           
     óö	  € V P                    F  p\        W!9   RV R24       K  	  VR,          VR,          rCVR,          P                  4       VR,          P                  4       reVR,          P                  4       VR,          P                  4       r‡\        WWWh.R4       \        VP                  P
                  V P                  P
                  8H  R4       \        \        P                  VP                  u;8H  ;'       d@    VP                  u;8H  ;'       d(    VP                  u;8H  ;'       d    VP                  8H  Mu R4       \        V. RO4       \        V. RO4       \        V. RO4       \        V. RO4       \        VP                  ^,          VP                  ^,          8H  R	4       \        VP                  ^,          VP                  ^,          8H  R	4       \        VP                  ^,          VP                  ^,          8H  R
4       VP                  R4      VP                  R4      r©V	e   T	MVR,          P                  R R RRR!1,          p	V
e   T
MVR,          P                  R R RRR!1,          p
\        WYR7      p\        WjR7      pVR!8¬  V^8*  ,          P                  4       VR!8¬  V^8*  ,          P                  4       ,          p\        \        V4      \        4       RVRVRVRV/pRR.pV P                   P#                  4       pVP%                  4        F`  w  ppVP'                  VV P                  P
                  ^ \(        P                  \+        VP                  4      VP-                  4       R7       Kb  	  V F+  pVP/                  VV P                  P
                  ^ R7       K-  	  V P                   P1                  V4       VP3                  4       w  pp\5        VRV4      p\5        VRV4      p\7        VR4      '       dg   \7        VR4      '       dU   \7        VR4      '       dC   \7        VR4      '       d1   R\        P8                  ! V4      R\        P8                  ! V4      /pV# R\        P:                  ! VP=                  4       4      P?                  V P                  4      R\        P:                  ! VP=                  4       4      P?                  V P                  4      /pV# )"a�  Match keypoints and descriptors between two images.

The output contains the matches (the indices of the matching keypoint pairs between the first and second image)
and the corresponding confidence scores.
Only a batch size of 1 is supported.

Args:
    data: Dictionary containing both images and the keypoints and descriptors thereof.

Returns:
    Dictionary containing the matches and scores.

``data`` (``dict``):
    ``image0`` (``dict``):
        ``keypoints`` (`float32`): ``(1, M, 2)``

        ``descriptors`` (`float32`): ``(1, M, D)``

        ``image``: ``(1, C, H, W)`` or ``image_size``: ``(1, 2)``

    ``image1`` (``dict``):
        ``keypoints`` (`float32`): ``(1, N, 2)``

        ``descriptors`` (`float32`): ``(1, N, D)``

        ``image``: ``(1, C, H, W)`` or ``image_size``: ``(1, 2)``

``output`` (``dict``):
    ``matches`` (`int64`): ``(S, 2)``

    ``scores`` (`float32`): ``(S,)``

zMissing key z in datar   r   Ú	keypointsÚdescriptorszWrong devicezWrong dtypez8Number of keypoints does not match number of descriptorsz$Descriptors' dimensions do not matchÚ
image_sizeNÚimage)ÚsizeÚkpts0Úkpts1Údesc0Údesc1Úmatches0Úmscores0)Údevice_typeÚ	device_idÚelement_typeÚshapeÚ
buffer_ptr)rN   rO   Ú	_ortvalueÚ
__dlpack__Ú__dlpack_device__ÚmatchesÚscores)Ú1ÚMÚ2)rX   ÚNrZ   )rX   rY   ÚD)rX   r[   r\   éþÿÿÿéÿÿÿÿ) r   r   Ú
contiguousr   r   r0   r/   Úfloat32Údtyper   rQ   Úgetr   ÚallÚboolÚ_KEYPOINT_RANGE_MSGr4   Ú
io_bindingÚitemsÚ
bind_inputÚ_npÚtupleÚdata_ptrÚbind_outputÚrun_with_iobindingÚget_outputsÚgetattrÚhasattrÚfrom_dlpackÚ
from_numpyr	   Úto)r5   r<   ÚkeyÚdata0Údata1Úkpts0_Úkpts1_rJ   rK   Úsize0Úsize1rH   rI   ÚinsideÚlightglue_inputsÚlightglue_outputsÚbindingÚnameÚtensorrV   ÚmscoresÚ_mÚ_sÚoutputss   &&                      r   r>   ÚOnnxLightGlue.forward‚   sü  € ðF ×*Ô*ˆCÜ˜™¨°S°E¸Ð&BÖCñ +à˜H•~ t¨H¥~ˆuØ˜{Õ+×6Ñ6Ó8¸%ÀÕ:L×:WÑ:WÓ:Y�Ø˜]Õ+×6Ñ6Ó8¸%ÀÕ:N×:YÑ:YÓ:[ˆuÜ! 6°&Ð"@À.ÔQÜ�V—]‘]×'Ñ'¨4¯;©;×+;Ñ+;Ñ;¸^ÔLÜ”U—]‘] f§l¡l×`Ô`°f·l±l×`Ô`ÀeÇkÁk×`Ô`ÐUZ×U`ÑU`Ô`ÐboÔpÜ˜6¢?Ô3Ü˜6¢?Ô3Ü˜5¢/Ô2Ü˜5¢/Ô2Ü�V—\‘\ !•_¨¯©°A­Ñ6Ð8rÔsÜ�V—\‘\ !•_¨¯©°A­Ñ6Ð8rÔsÜ�U—[‘[ •^ u§{¡{°1¥~Ñ5Ð7]Ô^ð —y‘y Ó.°·	±	¸,Ó0GˆuØÒ*‘°°gµ×0DÑ0DÀRÀSÐ0IÉ$ÈBÈ$Õ0OˆØÒ*‘°°gµ×0DÑ0DÀRÀSÐ0IÉ$ÈBÈ$Õ0Oˆä# FÔ7ˆÜ# FÔ7ˆð ˜B‘; 5¨A¡:Õ.×3Ñ3Ó5¸%À2¹+È%ÐSTÉ*Õ9U×8ZÑ8ZÓ8\Õ\ˆÜ”T˜&“\Ô#6Ô7ð $ U¨G°U¸GÀUÈGÐUZÐ[ÐØ'¨Ð4ÐØ—,‘,×)Ñ)Ó+ˆà,×2Ñ2Ö4‰LˆD�&Ø×ÑØØ ŸK™K×,Ñ,ØÜ Ÿ[™[Ü˜FŸL™LÓ)Ø!Ÿ?™?Ó,ð ö ñ 5ó &ˆDØ×Ñ °$·+±+×2BÑ2BÈaÐÖPñ &ð 	�‰×'Ñ'¨Ô0à"×.Ñ.Ó0Ñˆ�ô �W˜k¨7Ó3ˆÜ�W˜k¨7Ó3ˆä�B˜×%Ò%Ü˜Ð/×0Ò0Ü˜˜L×)Ò)Ü˜Ð/×0Ò0ð œ5×,Ò,¨RÓ0Øœ%×+Ò+¨BÓ/ðˆGð ˆð œ5×+Ò+¨G¯M©M«OÓ<×?Ñ?ÀÇÁÓLØœ%×*Ò*¨7¯=©=«?Ó;×>Ñ>¸t¿{¹{ÓKðˆGð ˆr"   )r   r4   )Nr$   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__annotations__r   r8   r?   r>   Ú__static_attributes__r   r"   r   r   r   )   s_   ‡ ñ"ðJ 	ÐpØÐ|ØÐzØð  Gð	,€JÐ(ó ð 08¸Ð.BÐÐ+ÓB÷Kõ@	"÷nñ nr"   )Ú
__future__r   Úimportlib.utilr,   Útypingr   r   r/   Úkornia.core.checkr   r   r   Úkornia.core.externalr	   ri   r
   r*   Úutilsr   r   re   Ú__all__r   r   r"   r   Ú<module>r”      sC   ðõ$ #ã ß "ã ç YÑ YÝ -Ý 4ç >ðDð ð Ð
€÷Gó Gr"   