ó
    ‡Ž¡j°  ã                   ó²   • S SK Jr  SSKJrJr  SSKJr  SSKJr  SSK	J
r
  \" 5       (       a  S SKr\(       a  S	S
KJr   " S S\
5      r " S S\5      rSS/rg)é    )ÚTYPE_CHECKINGé   )Ú
TensorTypeÚis_torch_available)Úrequiresé   )ÚSuperGlueImageProcessorPil)ÚSuperGlueImageProcessorNé   )Ú$EfficientLoFTRKeypointMatchingOutputc                   ód   • \ rS rSr S
SSS\\\   -  S\S\\\	\
R                  4      4S jjrSrg	)ÚEfficientLoFTRImageProcessoré   Úoutputsr   Útarget_sizesÚ	thresholdÚreturnc                 óF  • UR                   R                  S   [        U5      :w  a  [        S5      e[	        S U 5       5      (       d  [        S5      e[        U[        5      (       a)  [        R                  " X!R                   R                  S9nO3UR                  S   S:w  d  UR                  S   S:w  a  [        S5      eUnUR                  R                  5       nXTR                  S5      R                  SSSS5      -  nUR                  [        R                  5      n/ n[!        XQR                   UR"                  5       HX  u  pxn	[        R$                  " X“:„  US:„  5      n
US   U
S      nUS   U
S      nU	S   U
S      nUR'                  UUUS	.5        MZ     U$ )
á}  
Converts the raw output of [`EfficientLoFTRKeypointMatchingOutput`] into lists of keypoints, scores and descriptors
with coordinates absolute to the original image sizes.
Args:
    outputs ([`EfficientLoFTRKeypointMatchingOutput`]):
        Raw outputs of the model.
    target_sizes (`torch.Tensor` or `List[Tuple[Tuple[int, int]]]`, *optional*):
        Tensor of shape `(batch_size, 2, 2)` or list of tuples of tuples (`Tuple[int, int]`) containing the
        target size `(height, width)` of each image in the batch. This must be the original image size (before
        any processing).
    threshold (`float`, *optional*, defaults to 0.0):
        Threshold to filter out the matches with low scores.
Returns:
    `List[Dict]`: A list of dictionaries, each dictionary containing the keypoints in the first and second image
    of the pair, the matching scores and the matching indices.
r   úRMake sure that you pass in as many target sizes as the batch dimension of the maskc              3   ó>   #   • U  H  n[        U5      S :H  v •  M     g7f©r   N©Úlen©Ú.0Útarget_sizes     ÚÇC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/models/efficientloftr/modular_efficientloftr.pyÚ	<genexpr>ÚNEfficientLoFTRImageProcessor.post_process_keypoint_matching.<locals>.<genexpr>)   ó   é € ÐIºL¨[”3�{Ó# qÖ(ºLùó   ‚úTEach element of target_sizes must contain the size (h, w) of each image of the batch©Údevicer   r   éÿÿÿÿ©Ú
keypoints0Ú
keypoints1Úmatching_scores)ÚmatchesÚshaper   Ú
ValueErrorÚallÚ
isinstanceÚlistÚtorchÚtensorr%   Ú	keypointsÚcloneÚflipÚreshapeÚtoÚint32Úzipr*   Úlogical_andÚappend)Úselfr   r   r   Úimage_pair_sizesr3   ÚresultsÚkeypoints_pairr+   ÚscoresÚvalid_matchesÚmatched_keypoints0Úmatched_keypoints1r*   s                 r   Úpost_process_keypoint_matchingÚ;EfficientLoFTRImageProcessor.post_process_keypoint_matching   s“  € ð, �?‰?× Ñ  Ñ#¤s¨<Ó'8Ó8ÜÐqÓrÐrÜÑI¹LÓI×IÑIÜÐsÓtÐtä�l¤D×)Ñ)Ü$Ÿ|š|¨LÇÁ×AWÑAWÑXÑà×!Ñ! !Ñ$¨Ó)¨\×-?Ñ-?ÀÑ-BÀaÓ-GÜ Øjóð ð  ,Ðà×%Ñ%×+Ñ+Ó-ˆ	Ø× 5Ñ 5°bÓ 9× AÑ AÀ"ÀaÈÈAÓ NÑNˆ	Ø—L‘L¤§¡Ó-ˆ	àˆÜ/2°9¿o¹oÈw×OfÑOfÖ/gÑ+ˆN Vä!×-Ò-¨fÑ.@À'ÈBÁ,ÓOˆMà!/°Ñ!2°=ÀÑ3CÑ!DÐØ!/°Ñ!2°=ÀÑ3CÑ!DÐØ$ Q™i¨°aÑ(8Ñ9ˆOà�N‰Nà"4Ø"4Ø'6ñöñ 0hð  ˆó    © N©g        )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r0   ÚtupleÚfloatÚdictÚstrr1   ÚTensorrD   Ú__static_attributes__rG   rF   r   r   r      sS   † ð
 ñ	9à7ð9ð ! 4¨¡;Ñ.ð9ð ð	9ð
 
ˆd�3˜Ÿ™Ð$Ñ%Ñ	&÷9ð 9rF   r   c                   ób   • \ rS rSr\" SS9 SSSS\\\   -  S\S\\	\
S	4      4S
 jj5       rSrg)ÚEfficientLoFTRImageProcessorPiléM   )r1   )Úbackendsr   r   r   r   r   ztorch.Tensorc                 ó6  • SSK nUR                  R                  S   [        U5      :w  a  [	        S5      e[        S U 5       5      (       d  [	        S5      e[        U[        5      (       a%  UR                  " X!R                  R                  S9nO3UR                  S   S:w  d  UR                  S   S:w  a  [	        S5      eUnUR                  R                  5       nXeR                  S	5      R                  S	SSS5      -  nUR                  UR                  5      n/ n[!        XaR                  UR"                  5       HT  u  p‰n
UR$                  " X£:„  U	S	:„  5      nUS   US      nUS   US      nU
S   US      nUR'                  UUUS
.5        MV     U$ )r   r   Nr   c              3   ó>   #   • U  H  n[        U5      S :H  v •  M     g7fr   r   r   s     r   r   ÚQEfficientLoFTRImageProcessorPil.post_process_keypoint_matching.<locals>.<genexpr>i   r!   r"   r#   r$   r   r   r&   r'   )r1   r+   r,   r   r-   r.   r/   r0   r2   r%   r3   r4   r5   r6   r7   r8   r9   r*   r:   r;   )r<   r   r   r   r1   r=   r3   r>   r?   r+   r@   rA   rB   rC   r*   s                  r   rD   Ú>EfficientLoFTRImageProcessorPil.post_process_keypoint_matchingN   s–  € ó. 	à�?‰?× Ñ  Ñ#¤s¨<Ó'8Ó8ÜÐqÓrÐrÜÑI¹LÓI×IÑIÜÐsÓtÐtä�l¤D×)Ñ)Ø$Ÿ|š|¨LÇÁ×AWÑAWÑXÑà×!Ñ! !Ñ$¨Ó)¨\×-?Ñ-?ÀÑ-BÀaÓ-GÜ Øjóð ð  ,Ðà×%Ñ%×+Ñ+Ó-ˆ	Ø× 5Ñ 5°bÓ 9× AÑ AÀ"ÀaÈÈAÓ NÑNˆ	Ø—L‘L §¡Ó-ˆ	àˆÜ/2°9¿o¹oÈw×OfÑOfÖ/gÑ+ˆN Và!×-Ò-¨fÑ.@À'ÈBÁ,ÓOˆMà!/°Ñ!2°=ÀÑ3CÑ!DÐØ!/°Ñ!2°=ÀÑ3CÑ!DÐØ$ Q™i¨°aÑ(8Ñ9ˆOà�N‰Nà"4Ø"4Ø'6ñöñ 0hð  ˆrF   rG   NrH   )rI   rJ   rK   rL   r   r   r0   rM   rN   rO   rP   rD   rR   rG   rF   r   rT   rT   M   s\   † Ù�zÑ"ð
 ñ	;à7ð;ð ! 4¨¡;Ñ.ð;ð ð	;ð
 
ˆd�3˜Ð&Ñ'Ñ	(ô;ó #ó;rF   rT   )Útypingr   Úutilsr   r   Úutils.import_utilsr   Ú(superglue.image_processing_pil_supergluer	   Ú$superglue.image_processing_supergluer
   r1   Úmodeling_efficientloftrr   r   rT   Ú__all__rG   rF   r   Ú<module>rb      sQ   ðÝ  ç 3Ý *Ý QÝ Jñ ×ÑÛæÝMô:Ð#:ô :ôz=Ð&@ô =ð@ *Ð+LÐ
M�rF   