
    9i~                         S SK JrJrJrJrJrJr  S SKrSSK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  S
SKJr  S
SKJr  \\\4   r\R4                   " S S\5      5       r\
" S5       " S S\5      5       rg)    )AnyDictListOptionalTupleUnionN   )pipeline_requires_extra   )	KptResult)	benchmark)	HPIConfig)PaddlePredictorOption   )(AutoParallelImageSimpleInferencePipeline)BasePipelinec                   >  ^  \ rS rSrSr    SS\S\S\S\S\	\
\\\4   \4      S	S4U 4S
 jjjr SS\
\\R                   4   S\S	\\R                   \R                   4   4S jjr SS\
\\\   \R                   \\R                      4   S\	\   S	\4S jjrSrU =r$ )_KeypointDetectionPipeline   zKeypoint Detection pipelineNconfigdevice	pp_optionuse_hpip
hpi_configreturnc                 r  > [         TU ]  X#XES9  US   S   n0 nSU l        SU;   a  US   US'   US   U l        SU;   a  US   US'   U R                  " U40 UD6U l        US   S   n0 nSU;   a  US   US'   S	U;   a  US	   US	'   U R                  " U40 UD6U l        U R
                  R                  U l        g)
ah  
Initializes the class with given configurations and options.

Args:
    config (Dict): Configuration dictionary containing model and other parameters.
    device (str): The device to run the prediction on. Default is None.
    pp_option (PaddlePredictorOption): Options for PaddlePaddle predictor. Default is None.
    use_hpip (bool, optional): Whether to use the high-performance
        inference plugin (HPIP) by default. Defaults to False.
    hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional):
        The default high-performance inference configuration dictionary.
        Defaults to None.
)r   r   r   r   
SubModulesObjectDetectionN	thresholdimgszKeypointDetectionflipuse_udp)super__init__det_thresholdcreate_model	det_model	kpt_model
input_sizekpt_input_size)	selfr   r   r   r   r   	model_cfgmodel_kwargs	__class__s	           w/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/pipelines/keypoint_detection/pipeline.pyr%   #_KeypointDetectionPipeline.__init__"   s    * 	 	 	

 <():;	!)#(1+(>L%!*;!7Di$-g$6L!**9EE <()<=	Y#,V#4L 	!&/	&:L#**9EE"nn77    bboxpaddingc                    USS u  p4pV[         R                  " X5-   XF-   /5      S-  nU R                  S   U R                  S   -  nXS-
  Xd-
  pXU
-  :  a  X-  n
OXU
-  :  a  X-  n	[         R                  " X/5      U-  nX{4$ )aE  
Convert bounding box from (x1, y1, x2, y2) to center and scale.

Args:
    bbox (Union[Number, np.ndarray]): The bounding box coordinates (x1, y1, x2, y2).
    padding (float): The padding factor to adjust the scale of the bounding box.

Returns:
    Tuple[np.ndarray, np.ndarray]: The center and scale of the bounding box.
Nr	   g      ?r      )nparrayr+   )r,   r3   r4   x1y1x2y2centeraspect_ratiowhscales               r0   _box_xyxy2cs'_KeypointDetectionPipeline._box_xyxy2csQ   s     bq27BG,-3 **1-0C0CA0FFw1a A!! A! 7*}r2   inputr&   c           
   +   x  #    Uc  U R                   OUnU R                  XS9 H  nUS   US   peXe/ S.nUS    Hk  nU R                  US   5      u  p[        U R	                  UU	U
S.5      5      S	   nUS   R                  US   US
   US   S	   S   US   S	   S   S.5        Mm     [        U5      v   M     g7f)a  Predicts image classification results for the given input.

Args:
    input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
    det_threshold (float): The detection threshold. Defaults to None.
    **kwargs: Additional keyword arguments that can be passed to the function.

Returns:
    KptResult: The predicted KeyPoint Detection results.
N)r   	input_img
input_path)rG   rF   boxesrH   
coordinate)imgr=   rA   r   scorekpts	keypoints	kpt_score)rI   	det_scorerM   rN   )r&   r(   rB   listr)   appendr   )r,   rD   r&   kwargsdet_resori_imgimg_pathsingle_img_resboxr=   rA   kpt_ress               r0   predict"_KeypointDetectionPipeline.predictm   s       /<.C**~~e~EG ' 4gl6KX,4UWXNw' $ 1 1#l2C DNN#*&,%*  w'..&),&7%(\%,V_Q%7%D%,V_Q%7%D	 (& N++- Fs   B8B:)r(   r&   r+   r)   )NNFN)g      ?N)__name__
__module____qualname____firstlineno____doc__r   strr   boolr   r   r   r   r%   Numberr7   ndarrayfloatr   rB   r   r   rY   __static_attributes____classcell__)r/   s   @r0   r   r      s   %
 +/AE-8-8 -8 )	-8
 -8 U4S>9#<=>-8 
-8 -8` AE&"**,-8=	rzz2::%	&> *.',S$s)RZZbjj1AAB',  ',
 
', ',r2   r   cvc                   .    \ rS rSrSr\S 5       rS rSrg)KeypointDetectionPipeline   human_keypoint_detectionc                     [         $ r[   )r   )r,   s    r0   _pipeline_cls'KeypointDetectionPipeline._pipeline_cls   s    ))r2   c                 2    US   S   R                  SS5      $ )Nr   r   
batch_sizer6   )get)r,   r   s     r0   _get_batch_size)KeypointDetectionPipeline._get_batch_size   s     l#$56::<KKr2    N)	r\   r]   r^   r_   entitiespropertyrn   rs   rf   ru   r2   r0   rj   rj      s    )H* *Lr2   rj   )typingr   r   r   r   r   r   numpyr7   
utils.depsr
    models.keypoint_detection.resultr   utils.benchmarkr   	utils.hpir   utils.pp_optionr   	_parallelr   baser   intre   rc   time_methodsr   rj   ru   r2   r0   <module>r      s|    ; :  2 9 ( " 4 @ 	sEz	 u, u, u,p L H L Lr2   