
    @Ki,                        % S SK Jr  S SKJrJrJr  S SKJrJr  SSK	J
r
  SSKJrJr  SSKJr  \" 5       (       a  S S	KJr  SS
K	Jr  \\S\4      r\\S'    " S S\5      r " S S\5      rS\S\\\      4S jr " S S\5      rg)    )Sequence)Any	TypedDictUnion)	TypeAliasoverload   )is_pil_image)is_vision_availablerequires_backends   )Pipeline)Image)
load_imagezImage.Image	ImagePairc                   *    \ rS rSr% \\S'   \\S'   Srg)Keypoint"   xy N)__name__
__module____qualname____firstlineno__float__annotations____static_attributes__r       j/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/transformers/pipelines/keypoint_matching.pyr   r   "   s    HHr   r   c                   4    \ rS rSr% \\S'   \\S'   \\S'   Srg)Match'   keypoint_image_0keypoint_image_1scorer   N)r   r   r   r   r   r   r   r   r   r   r    r"   r"   '   s    Lr   r"   imagesreturnc                    ^ SnS m[        U [        5      (       aH  [        U 5      S:X  a  [        U4S jU  5       5      (       a  U /$ [        U4S jU  5       5      (       a  U $ [	        U5      e)N)z-Input images must be a one of the following :z - A pair of images.z - A list of pairs of images.c                 F    [        U 5      =(       d    [        U [        5      $ )z"images is a PIL Image or a string.)r
   
isinstancestr)images    r    _is_valid_image-validate_image_pairs.<locals>._is_valid_image4   s    E"<j&<<r   r	   c              3   4   >#    U  H  nT" U5      v   M     g 7fNr   .0r-   r.   s     r    	<genexpr>'validate_image_pairs.<locals>.<genexpr>9   s     #Q&_U%;%;&   c              3      >#    U  HF  n[        U[        5      =(       a*    [        U5      S :H  =(       a    [        U4S jU 5       5      v   MH     g7f)r	   c              3   4   >#    U  H  nT" U5      v   M     g 7fr1   r   r2   s     r    r4   1validate_image_pairs.<locals>.<genexpr>.<genexpr>>   s     C
uOE**
r6   N)r+   r   lenall)r3   
image_pairr.   s     r    r4   r5   ;   sO      
 %
 z8, DJ1$DC
CCD %s   AA)r+   r   r:   r;   
ValueError)r'   error_messager.   s     @r    validate_image_pairsr?   -   so    M= &(##v;!#Q&#Q Q Q8O 
 %	
 
 
 M
]
##r   c                   (  ^  \ rS rSrSrSrSrSrSrU 4S jr	SS jr
\SS\S\S	\S
\\   4S jj5       r\SS\\   S\S	\S
\\\      4S jj5       r SS\\\   \4   S\S	\S
\\\   \\\      4   4U 4S jjjrSS jrS rSS
\\   4S jjrSrU =r$ )KeypointMatchingPipelineE   zz
Keypoint matching pipeline using any `AutoModelForKeypointMatching`. This pipeline matches keypoints between two images.
FTc                 t   > [         TU ]  " U0 UD6  [        U S5        U R                  S:w  a  [	        S5      eg )NvisionptzBKeypoint matching pipeline only supports PyTorch (framework='pt').)super__init__r   	frameworkr=   )selfargskwargs	__class__s      r    rG   !KeypointMatchingPipeline.__init__O   s<    $)&)$)>>T!abb "r   c                 0    0 nUb  X#S'   0 nUb  XS'   U0 U4$ )Ntimeout	thresholdr   )rI   rP   rO   preprocess_paramspostprocess_paramss        r    _sanitize_parameters-KeypointMatchingPipeline._sanitize_parametersU   s8    +2i( .7{+ "&888r   inputsrP   rK   r(   c                     g r1   r   rI   rU   rP   rK   s       r    __call__!KeypointMatchingPipeline.__call__^   s    adr   c                     g r1   r   rW   s       r    rX   rY   a   s    mpr   c                    > Uc  [        S5      e[        U5      n[        TU ]  " U4SU0UD6n[	        U5      S:X  a  US   $ U$ )a0  
Find matches between keypoints in two images.

Args:
    inputs (`str`, `list[str]`, `PIL.Image` or `list[PIL.Image]`):
        The pipeline handles three types of images:

        - A string containing a http link pointing to an image
        - A string containing a local path to an image
        - An image loaded in PIL directly

        The pipeline accepts either a single pair of images or a batch of image pairs, which must then be passed as a string.
        Images in a batch must all be in the same format: all as http links, all as local paths, or all as PIL
        images.

    threshold (`float`, *optional*, defaults to 0.0):
        The threshold to use for keypoint matching. Keypoints matched with a lower matching score will be filtered out.
        A value of 0 means that all matched keypoints will be returned.

    kwargs:
        `timeout (`float`, *optional*, defaults to None)`
            The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
            the call may block forever.

Return:
    Union[list[Match], list[list[Match]]]:
        A list of matches or a list if a single image pair is provided, or of lists of matches if a batch
        of image pairs is provided. Each match is a dictionary containing the following keys:

        - **keypoint_image_0** (`Keypoint`): The keypoint in the first image (x, y coordinates).
        - **keypoint_image_1** (`Keypoint`): The keypoint in the second image (x, y coordinates).
        - **score** (`float`): The matching score between the two keypoints.
zFCannot call the keypoint-matching pipeline without an inputs argument!rP   r   r   )r=   r?   rF   rX   r:   )rI   rU   rP   rK   formatted_inputsoutputsrL   s         r    rX   rY   d   sY    N >eff/7'"#3SySFS A%1:r   c                     U Vs/ s H  n[        X2S9PM     nnU R                  XR                  S9nUR                  U R                  5      nU Vs/ s H  o3R
                  PM     nnXES.nU$ s  snf s  snf )N)rO   )r'   return_tensors)model_inputstarget_sizes)r   image_processorrH   todtypesize)rI   r'   rO   r-   r`   ra   preprocess_outputss          r    
preprocess#KeypointMatchingPipeline.preprocess   st    BHI&*U4&I++6..+Y#tzz2067u

7.:Y!! J 8s   A/A4c                 D    US   nU R                   " S0 UD6nX1S   /S.nU$ )Nr`   ra   )model_outputsra   r   )model)rI   rf   r`   rj   forward_outputss        r    _forward!KeypointMatchingPipeline._forward   s4    ).9

2\2,9_mLnKopr   c           	         US   nUS   nU R                   R                  X4US9nUS   n/ n[        US   US   US   5       H  u  pxn	[        US   R	                  5       US   R	                  5       S	9n[        US   R	                  5       US   R	                  5       S	9nUR                  [        XxU	R	                  5       S
95        M     [        US SS9nU$ )Nrj   ra   )ra   rP   r   
keypoints0
keypoints1matching_scoresr   )r   r   )r$   r%   r&   c                     U S   $ )Nr&   r   )r   s    r    <lambda>6KeypointMatchingPipeline.postprocess.<locals>.<lambda>   s    '
r   T)keyreverse)rb   post_process_keypoint_matchingzipr   itemappendr"   sorted)
rI   rl   rP   rj   ra   postprocess_outputspair_resultkp_0kp_1r&   s
             r    postprocess$KeypointMatchingPipeline.postprocess   s    '8&~6"22QQ	 R 
 2!4!$-- 12"
D
 d1gllnQ?Dd1gllnQ?DudY^YcYcYefg"
 [.BDQr   r   )NN)g        r1   )r   r   r   r   __doc___load_processor_load_image_processor_load_feature_extractor_load_tokenizerrG   rS   r   r   r   r   listr"   rX   r   rg   rm   r   r   __classcell__)rL   s   @r    rA   rA   E   s    O #Oc9 dydUdCdTXY^T_d dptIp5pRUpZ^_cdi_jZkp p
 -d9oy01- - 	-
 
tE{De--	.- -^"T%[  r   rA   N)collections.abcr   typingr   r   r   typing_extensionsr   r   image_utilsr
   utilsr   r   baser   PILr   r   r,   r   r   r   r"   r?   rA   r   r   r    <module>r      s    % ( ( 1 & :  (  mS&8 9:	9 :y 
I $ $(92E)F $0mx mr   