
    Z 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     ڊ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/efficientloftr/modular_efficientloftr.py	<genexpr>NEfficientLoFTRImageProcessor.post_process_keypoint_matching.<locals>.<genexpr>)        IL[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ILIIIsttlD))$||LAWAWX!!!$)\-?-?-Ba-G j   ,%%++-	 5 5b 9 A A"aA NN	LL-	/29oowOfOf/g+NV!--f.@'B,OM!/!2=3C!D!/!2=3C!D$Qia(89ONN"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
 
d3$%	&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)EfficientLoFTRImageProcessorPilM   )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  pn
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ILIIIsttlD))$||LAWAWX!!!$)\-?-?-Ba-G j   ,%%++-	 5 5b 9 A A"aA NN	LL-	/29oowOfOf/g+NV!--f.@'B,OM!/!2=3C!D!/!2=3C!D$Qia(89ONN"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;.; 	;
 
d3&'	(; #;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   