+
    œ°³j–1  ã                   óJ  € ^ RI Ht ^ RIHtHt ^ RIHt ^RIH	t	 ^RI
Ht ^RIHtHt ^RIHt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Ht ]! 4       '       d   ^ R
It]'       d   ^RI H!t!  ! R R]RR7      t"R t#R R lt$R R lt%R R lt&] ! R R]	4      4       t'R.t(R
# )é    )ÚTYPE_CHECKING)ÚImageÚ	ImageDraw)Ú
functional)ÚTorchvisionBackend)ÚBatchFeature)Úgroup_images_by_shapeÚreorder_images)Ú
ImageInputÚ	ImageTypeÚPILImageResamplingÚSizeDictÚget_image_typeÚis_pil_imageÚis_valid_imageÚto_numpy_array)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringÚis_torch_availableN)Ú$EfficientLoFTRKeypointMatchingOutputc                   ó0   a € ] tR t^$t o RtV 3R ltRtV tR# )Ú"EfficientLoFTRImageProcessorKwargsz´
do_grayscale (`bool`, *optional*, defaults to `self.do_grayscale`):
    Whether to convert the image to grayscale. Can be overridden by `do_grayscale` in the `preprocess` method.
c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )é   Údo_grayscale)Úbool)ÚformatÚ__classdict__s   "€Úƒ/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/efficientloftr/image_processing_efficientloftr.pyÚ__annotate__Ú/EfficientLoFTRImageProcessorKwargs.__annotate__$   s   ø‡ ‚ ñ Ñò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r    s   @r!   r   r   $   s   ø‡ € ñ÷ ƒ r$   r   F)Útotalc                 óÆ   € \        V 4      ;'       gP    \        V 4      ;'       d=    \        V 4      \        P                  8g  ;'       d    \        V P                  4      ^8H  # )é   ©r   r   r   r   ÚPILÚlenÚshape©Úimages   &r!   Ú_is_valid_imager7   -   sQ   € Ü˜Ó÷ ð Ü�uÓ×bÐb¤.°Ó"7¼9¿=¹=Ñ"H×bÐbÌSÐQV×Q\ÑQ\ÓM]ÐabÑMbðr$   c                ó$   € V ^8„  d   QhR\         /# )r   Úimages©r   )r   s   "r!   r"   r"   3   s   € ÷ $ñ $¬Jñ $r$   c                 ó¶  a€ RpR o\        V \        4      '       d®   \        V 4      ^8X  dC   \        ;QJ d    V3R lV  4       F  '       d   K   RM	  RM! V3R lV  4       4      '       d   V # \        ;QJ d    V3R lV  4       F  '       d   K   RM	  RM! V3R lV  4       4      '       d   V  UUu. uF  q" F  q3NK  	  K  	  upp# \	        V4      hu uppi )ú-Input images must be a one of the following :c                óÆ   € \        V 4      ;'       gP    \        V 4      ;'       d=    \        V 4      \        P                  8g  ;'       d    \        V P                  4      ^8H  # )z$images is a PIL Image or a 3D array.r1   r5   s   &r!   r7   Ú8validate_and_format_image_pairs.<locals>._is_valid_image<   sR   € ä˜EÓ"÷ 
ð 
Ü˜5Ó!×fÐf¤n°UÓ&;¼y¿}¹}Ñ&L×fÐfÔQTÐUZ×U`ÑU`ÓQaÐefÑQfð	
r$   c              3   ó4   <"  € T F  pS! V4      x € K  	  R # 5i©Nr%   ©Ú.0r6   r7   s   & €r!   Ú	<genexpr>Ú2validate_and_format_image_pairs.<locals>.<genexpr>C   s   øé € Ð#QÉ&À¡_°U×%;Ð%;Ë&ùó   ƒFTc              3   óô   <"  € T Fm  p\        V\        4      ;'       dQ    \        V4      ^8H  ;'       d;    \        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      x € Ko  	  R# 5i)r   c              3   ó4   <"  € T F  pS! V4      x € K  	  R # 5ir@   r%   rA   s   & €r!   rC   Ú<validate_and_format_image_pairs.<locals>.<genexpr>.<genexpr>H   s   øé € ÐC¹
¨u‘O E×*Ð*»
ùrE   FTN)Ú
isinstanceÚlistr3   Úall)rB   Ú
image_pairr7   s   & €r!   rC   rD   E   sk   øé € ð 
ñ %�
ô �z¤4Ó(÷ Dð DÜ�J“ 1Ñ$÷Dð Dç“ÔC¹
ÓC——’ÔC¹
ÓCÓCôDó %ùs   ƒA8ŸA8µA8ÁA8Á A8)r<   z - A pair of PIL images.z - A pair of 3D arrays.z! - A list of pairs of PIL images.z  - A list of pairs of 3D arrays.)rI   rJ   r3   rK   Ú
ValueError)r9   Úerror_messagerL   r6   r7   s   &   @r!   Úvalidate_and_format_image_pairsrO   3   s²   ø€ ð€Mò
ô �&œ$×ÒÜˆv‹;˜!Ô§£Ô#QÉ&Ó#Q§§¢Ô#QÉ&Ó#Q× QÒ QØˆMß‹3ô 
ñ %ó	
�3�3Š3ô 
ñ %ó	
÷ 
ò 
ñ -3ÔK©F˜jÂ
°u’EÁ
‘E©FÒKÐKÜ
�]Ó
#Ð#ùó Ls   Â4Cc                ó   € V ^8„  d   QhRR/# )r   r6   útorch.Tensorr%   )r   s   "r!   r"   r"   O   s   € ÷ ñ Øñr$   c                ó*  € V P                   ^8  g,   V P                  V P                   ^8X  d   ^ M^,          ^8X  d   R# \        P                  ! V R,          V R,          8H  4      ;'       d(    \        P                  ! V R,          V R,          8H  4      # )zAChecks if an image is grayscale (all RGB channels are identical).T).r   ºNNNrS   ).é   rS   rS   ).r   rS   rS   )Úndimr4   ÚtorchrK   r5   s   &r!   Úis_grayscalerW   O   sv   € ð ‡z�z�A„~˜Ÿ™¨%¯*©*¸¬/¡Q¸qÕAÀQÔFÙÜ�9Š9�U˜<Õ(¨E°,Õ,?Ñ?Ó@÷ ð ÄUÇYÂYØˆlÕ˜u \Õ2Ñ2óFð r$   c                ó    € V ^8„  d   QhRRRR/# )r   r6   rQ   Úreturnr%   )r   s   "r!   r"   r"   Z   s   € ÷ >ñ >Øð>àñ>r$   c                óX   € \        V 4      '       d   V # \        P                  ! V ^R7      # )a‘  
Converts an image to grayscale format using the NTSC formula. Only support torch.Tensor.

This function is supposed to return a 1-channel image, but it returns a 3-channel image with the same value in each
channel, because of an issue that is discussed in :
https://github.com/huggingface/transformers/pull/25786#issuecomment-1730176446

Args:
    image (torch.Tensor):
        The image to convert.
)Únum_output_channels)rW   ÚtvFÚrgb_to_grayscaler5   s   &r!   Úconvert_to_grayscaler^   Z   s'   € ô �E×ÒØˆÜ×Ò ¸1Ô=Ð=r$   c                   óö   a a€ ] tR t^mt o]t]P                  tRRRR/t	Rt
RtRtRtRtRtV3R lV 3R	 llt]V3R
 lV 3R ll4       tV3R lR ltRV3R lR lltRV3R lR lltV3R lR ltR tRtVtV ;t# )ÚEfficientLoFTRImageProcessorÚheightià  Úwidthi€  FTNc                ó0   <€ V ^8„  d   QhRS[ S[,          /# )r   Úkwargs)r   r   )r   r    s   "€r!   r"   Ú)EfficientLoFTRImageProcessor.__annotate__y   s   ø€ ÷ #ñ #¡Ñ(JÕ!Kñ #r$   c                ó(   <€ \         SV `  ! R/ VB  R # )Nr%   )ÚsuperÚ__init__)Úselfrd   Ú	__class__s   &,€r!   rh   Ú%EfficientLoFTRImageProcessor.__init__y   s   ø€ Ü‰ÒÑ"˜6Ô"r$   c                ó<   <€ V ^8„  d   QhRS[ RS[S[,          RS[/# )r   r9   rd   rY   )r   r   r   r   )r   r    s   "€r!   r"   re   }   s)   ø€ ÷ 4ñ 4¡ð 4±vÑ>`Õ7að 4Ñfrñ 4r$   c                ó&   <€ \         SV `  ! V3/ VB # r@   )rg   Ú
preprocess)ri   r9   rd   rj   s   &&,€r!   rn   Ú'EfficientLoFTRImageProcessor.preprocess|   s   ø€ ä‰wÒ! &Ñ3¨FÑ3Ð3r$   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# )r   r9   rY   r:   )r   r    s   "€r!   r"   re   €   s   ø€ ÷ 7ñ 7áð7ñ 
ñ	7r$   c                ó:   € V P                  V4      p\        V4      # r@   )Úfetch_imagesrO   )ri   r9   rd   s   &&,r!   Ú_prepare_images_structureÚ6EfficientLoFTRImageProcessor._prepare_images_structure€   s   € ð ×"Ñ" 6Ó*ˆÜ.¨vÓ6Ð6r$   c                óŽ   <€ V ^8„  d   QhRS[ R,          RS[RS[RRRS[RS[R	S[R
,          RS[S[,          R
,          RS[RS[/
# )r   r9   rQ   Ú	do_resizeÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚ
do_rescaleÚrescale_factorÚdisable_groupingNÚreturn_tensorsr   rY   )rJ   r   r   ÚfloatÚstrr   r   )r   r    s   "€r!   r"   re   ‰   s�   ø€ ÷ )^ñ )^á�^Õ$ð)^ñ ð)^ñ ð	)^ð
 Lð)^ñ ð)^ñ ð)^ñ  �+ð)^ñ ™jÕ(¨4Õ/ð)^ñ ð)^ñ 
ñ)^r$   c
                óP  € \        WR 7      w  r¼/ pVP                  4        F$  w  rïV'       d   V P                  WóVR7      pWýV&   K&  	  \        WÜ4      p\        VVR 7      w  r¼/ pVP                  4        F5  w  rïV'       d   V P	                  Wö4      pV	'       d   \        V4      pWýV&   K7  	  \        WÜ4      p\        ^ \        V4      ^4       Uu. uF  pVVV^,            NK  	  ppV Uu. uF  p\        P                  ! V^ R7      NK  	  pp\        RV/VR7      # u upi u upi ))r{   )rw   rx   )ÚdimÚpixel_values)ÚdataÚtensor_type)r	   ÚitemsÚresizer
   Úrescaler^   Úranger3   rV   Ústackr   )ri   r9   rv   rw   rx   ry   rz   r{   r|   r   rd   Úgrouped_imagesÚgrouped_images_indexÚprocessed_images_groupedr4   Ústacked_imagesÚresized_imagesÚprocessed_imagesÚiÚimage_pairsÚpairÚstacked_pairss   &&&&&&&&&&,           r!   Ú_preprocessÚ(EfficientLoFTRImageProcessor._preprocess‰   s0  € ô 0EÀVÔ/oÑ,ˆØ#%Ð à%3×%9Ñ%9Ö%;Ñ!ˆEßØ!%§¡¨^ÐQY Ó!Z�Ø.< UÓ+ñ &<ô (Ð(@ÓWˆä/DÀ^ÐfvÔ/wÑ,ˆØ#%Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆEßØ!%§¡¨nÓ!M�ßÜ!5°nÓ!E�Ø.< UÓ+ñ &<ô *Ð*BÓYÐô =BÀ!ÄSÐIYÓEZÐ\]Ô<^Ó_Ñ<^°qÐ'¨¨A°­EÓ2Ñ<^ˆÐ_ñ ?JÓJ¹k°dœŸš T¨q×1¹kˆÐJô  .°-Ð!@ÈnÔ]Ð]ùò `ùò Ks   ÃDÃ,!D#c                óŠ   <€ V ^8„  d   QhRRRS[ S[S[,          ,          RS[RS[S[S[S[P                  3,          ,          /# )r   Úoutputsr   Útarget_sizesÚ	thresholdrY   )r   rJ   Útupler}   Údictr~   rV   ÚTensor)r   r    s   "€r!   r"   re   ´   sO   ø€ ÷ 9ñ 9à7ð9ñ !¡4©¥;Õ.ð9ñ ð	9ñ
 
‰d‘3™Ÿ™Ð$Õ%Õ	&ñ9r$   c           	     ó  € VP                   P                  ^ ,          \        V4      8w  d   \        R4      h\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        R4      h\        V\        4      '       d-   \        P                  ! W!P                   P                  R7      pM=VP                  ^,          ^8w  g   VP                  ^,          ^8w  d   \        R4      hTpVP                  P                  4       pWTP                  R
4      P                  R
^^^4      ,          pVP                  \        P                  4      p. p\!        WQP                   VP"                  4       F~  w  rxp	\        P$                  ! W“8„  VR
8„  4      p
V^ ,          V
^ ,          ,          pV^,          V
^,          ,          pV	^ ,          V
^ ,          ,          pVP'                  RVRVR	V/4       K€  	  V# )a}  
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.
zRMake sure that you pass in as many target sizes as the batch dimension of the maskc              3   ó>   "  € T F  p\        V4      ^8H  x € K  	  R# 5i)r   N)r3   )rB   Útarget_sizes   & r!   rC   ÚNEfficientLoFTRImageProcessor.post_process_keypoint_matching.<locals>.<genexpr>Ì   s   é € ÐI¹L¨[”3�{Ó# qÖ(»Lùs   ‚FTzTEach element of target_sizes must contain the size (h, w) of each image of the batch)ÚdeviceÚ
keypoints0Ú
keypoints1Úmatching_scoreséÿÿÿÿ)Úmatchesr4   r3   rM   rK   rI   rJ   rV   Útensorr    Ú	keypointsÚcloneÚflipÚreshapeÚtoÚint32Úzipr£   Úlogical_andÚappend)ri   r–   r—   r˜   Úimage_pair_sizesr§   Ú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ß‹sÑI¹LÓI�s�sŠsÑ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Ø% ðöñ 0hð  ˆr$   c                ón   <€ V ^8„  d   QhRS[ S[S[S[P                  3,          ,          RS[ R,          /# )r   Úkeypoint_matching_outputrY   zImage.Image)rJ   rš   r~   rV   r›   )r   r    s   "€r!   r"   re   ï   s9   ø€ ÷ 5ñ 5ñ #'¡t©C±·±Ð,=Õ'>Õ"?ð5ñ 
ˆmÕ	ñ	5r$   c           	     óö  € \        V4      pV Uu. uF  p\        V4      NK  	  pp\        ^ \        V4      ^4       Uu. uF  qAWD^,            NK  	  pp. p\	        WR4       EF
  w  rxV^ ,          P
                  R,          w  ršV^,          P
                  R,          w  r¼\        P                  ! \        W›4      W¬,           ^3\        P                  R7      p\        P                  ! V^ ,          4      VRV	1RV
13&   \        P                  ! V^,          4      VRV1V
R13&   \        P                  ! VP                  4       4      p\        P                  ! V4      pVR,          P!                  ^4      w  ppVR,          P!                  ^4      w  pp\	        VVVVVR,          4       F­  w  pppppV P#                  V4      pVP%                  VVVV
,           V3V^R7       VP'                  V^,
          V^,
          V^,           V^,           3RR	7       VP'                  VV
,           ^,
          V^,
          VV
,           ^,           V^,           3RR	7       K¯  	  VP)                  V4       EK  	  V# u upi u upi )
a`  
Plots the image pairs side by side with the detected keypoints as well as the matching between them.

Args:
    images:
        Image pairs to plot. Same as `EfficientLoFTRImageProcessor.preprocess`. Expects either a list of 2
        images or a list of list of 2 images list with pixel values ranging from 0 to 255.
    keypoint_matching_output (List[Dict[str, torch.Tensor]]]):
        A post processed keypoint matching output

Returns:
    `List[PIL.Image.Image]`: A list of PIL images, each containing the image pairs side by side with the detected
    keypoints as well as the matching between them.
:Nr   N)ÚdtypeNr¡   r¢   r£   )Úfillrb   Úblack)r½   )rO   r   r‡   r3   r­   r4   rV   ÚzerosÚmaxÚuint8Ú
from_numpyr   Ú	fromarrayÚnumpyr   ÚDrawÚunbindÚ
_get_colorÚlineÚellipser¯   )ri   r9   rº   r6   r�   r�   r±   rL   Úpair_outputÚheight0Úwidth0Úheight1Úwidth1Ú
plot_imageÚplot_image_pilÚdrawÚkeypoints0_xÚkeypoints0_yÚkeypoints1_xÚkeypoints1_yÚkeypoint0_xÚkeypoint0_yÚkeypoint1_xÚkeypoint1_yÚmatching_scoreÚcolors   &&&                       r!   Úvisualize_keypoint_matchingÚ8EfficientLoFTRImageProcessor.visualize_keypoint_matchingï   sO  € ô( 1°Ó8ˆÙ5;Ó<±V¨E”. Ö'±VˆÐ<Ü27¸¼3¸v»;ÈÔ2JÓKÑ2J¨Q˜a a¥%Ó(Ñ2JˆÐKàˆÜ'*¨;×'QÑ#ˆJØ(¨�m×1Ñ1°"Õ5‰OˆGØ(¨�m×1Ñ1°"Õ5‰OˆGÜŸš¤c¨'Ó&;¸V½_ÈaÐ%PÔX]×XcÑXcÔdˆJÜ,1×,<Ò,<¸ZÈ½]Ó,KˆJ�x˜�x  & Ð(Ñ)Ü,1×,<Ò,<¸ZÈ½]Ó,KˆJ�x˜�x ¡Ð(Ñ)ä"Ÿ_š_¨Z×-=Ñ-=Ó-?Ó@ˆNÜ—>’> .Ó1ˆDà)4°\Õ)B×)IÑ)IÈ!Ó)LÑ&ˆL˜,Ø)4°\Õ)B×)IÑ)IÈ!Ó)LÑ&ˆL˜,ÜVYØ˜l¨L¸,ÈÐTeÕHföWÑR�˜[¨+°{ÀNð Ÿ™¨Ó7�Ø—	‘	Ø  +¨{¸VÕ/CÀ[ÐQØØð ô ð
 —‘˜k¨A�o¨{¸Q­ÀÈaÅÐQ\Ð_`ÕQ`ÐaÐho�ÔpØ—‘Ø  6Õ)¨AÕ-¨{¸Q­ÀÈfÕ@TÐWXÕ@XÐZeÐhiÕZiÐjØ ð ö ñWð �N‰N˜>×*ñ7 (Rð8 ˆùòA =ùÚKs
   �I1¾I6c                ód   € \        ^ÿ^V,
          ,          4      p\        ^ÿV,          4      p^ pW#V3# )zMaps a score to a color.)Úint)ri   ÚscoreÚrÚgÚbs   &&   r!   rÇ   Ú'EfficientLoFTRImageProcessor._get_color&  s1   € ä��q˜5•yÕ!Ó"ˆÜ��e•ÓˆØˆØ�Qˆwˆr$   r%   gp?)T)g        )r&   r'   r(   r)   r   Úvalid_kwargsr   ÚBILINEARrx   rw   Údefault_to_squarerv   ry   rz   Údo_normalizer   rh   r   rn   rs   r“   r·   rÜ   rÇ   r,   r-   Ú__classcell__)rj   r    s   @@r!   r`   r`   m   sœ   ù‡ € à5€LØ!×*Ñ*€HØ�c˜7 CÐ(€DØÐØ€IØ€JØ€NØ€LØ€L÷#ó #ð ÷4ò 4ó ð4÷7ð 7÷)^ò )^÷V9ò 9÷v5ð 5÷nò r$   r`   ))Útypingr   r2   r   r   Útorchvision.transforms.v2r   r\   Úimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr	   r
   Úimage_utilsr   r   r   r   r   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   rV   Úmodeling_efficientloftrr   r   r7   rO   rW   r^   r`   Ú__all__r%   r$   r!   Ú<module>rô      s“   ðõ !ç  Ý 7å ;Ý 2ß E÷	÷ 	ó 	÷ 5ß CÑ Cñ ×ÒÛçÝMô¨¸Uõ òõ$õ8õ>ð& ô}Ð#5ó }ó ð}ð@ *Ð
*‚r$   