Ë
    »dæj–G  ã                   ó¤  — d Z ddlZddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddl
mZ ddl
mZ dd	l
mZ dd
l
mZ ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ej@                  Z!ejD                  Z#ejH                  Z%ejL                  Z'ejP                  Z( ejR                  dejT                   ejV                  ejX                  «      ejZ                  ej\                  «      Z/ G d„ dej`                  «      Z1 ejd                  d ejV                  e1«       ejV                  ejZ                  «      f«       ejd                  dejZ                  ejZ                   ejV                  ejf                  «       ejV                  ejX                  «      f«       ejd                  dejZ                  ejZ                   ejV                  ejf                  «      ej\                   ejV                  ejX                  «      f«       ejd                  dejZ                  ejZ                   ejV                  ejf                  «      ej\                  f«       ejh                  d ejV                  ejX                  «      gd«       ejd                  dejZ                  f«      fZ5ejl                   G d„ d«      «       Z7 G d„ d«      Z8y)z"MediaPipe gesture recognizer task.é    N)ÚCallableÚOptionalÚTuple)Úclassifier_options)Úclassifier_options_c)Úasync_result_dispatcher)Úbase_options)Úbase_options_c)Úmediapipe_c_bindings)Úmediapipe_c_utils)Úserial_dispatcher)Údoc_controls)Úgesture_recognizer_result)Úgesture_recognizer_result_c)Úimage)Úimage_processing_options)Úimage_processing_options_c)Úvision_task_running_modec                   ó~  — e Zd ZdZdej
                  fdej                  fdej                  fdej                  fdej                  fdej                  fde	j                  fd	e	j                  fd
efg	Zeej                  dej
                  dededededede	j                  d	e	j                  d
ddd fd„«       «       Zy)ÚGestureRecognizerOptionsCz%C types for GestureRecognizerOptions.r	   Úrunning_modeÚ	num_handsÚmin_hand_detection_confidenceÚmin_hand_presence_confidenceÚmin_tracking_confidenceÚ"canned_gestures_classifier_optionsÚ"custom_gestures_classifier_optionsÚresult_callbackÚ_C_TYPES_RESULT_CALLBACKÚreturnc
                 ó8   —  | ||j                   |||||||	¬«	      S )zBCreates a GestureRecognizerOptionsC object from the given options.©	r	   r   r   r   r   r   r   r   r   )Úctype)
Úclsr	   r   r   r   r   r   r   r   r   s
             ús/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/mediapipe/tasks/python/vision/gesture_recognizer.pyÚfrom_c_optionsz(GestureRecognizerOptionsC.from_c_optionsK   s2   € ñ Ø!Ø!×'Ñ'ØØ&CØ%AØ 7Ø+MØ+MØ'ô
ð 
ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚBaseOptionsCÚctypesÚc_intÚc_floatr   ÚClassifierOptionsCr   Ú_fields_Úclassmethodr   Údo_not_generate_docsÚ_RunningModeÚintÚfloatr&   © r'   r%   r   r   7   s  „ Ù-à�~×2Ñ2Ð3Ø�v—|‘|Ð$Ø�F—L‘LÐ!Ø&¨¯©Ð7Ø% v§~¡~Ð6Ø  &§.¡.Ð1à
.Ø
×
1Ñ
1ðð
 /Ø
×
1Ñ
1ðð Ð2Ð3ð€(ð$ Ø×$Ñ$ðà"×/Ñ/ðð !ðð ð	ð
 &+ðð %*ðð  %ðð +?×*QÑ*Qðð +?×*QÑ*Qðð 2ðð #òó %ó ñr'   r   ÚMpGestureRecognizerCreateÚ!MpGestureRecognizerRecognizeImageÚ$MpGestureRecognizerRecognizeForVideoÚ!MpGestureRecognizerRecognizeAsyncÚMpGestureRecognizerCloseResultÚMpGestureRecognizerClosec                   ó  — e Zd ZU dZeed<   ej                  Zeed<   dZ	e
ed<   dZeed<   dZeed<   dZeed	<    ej                   e¬
«      Zeed<    ej                   e¬
«      Zeed<   dZeeeej2                  e
gdf      ed<   y)ÚGestureRecognizerOptionsaâ  Options for the gesture recognizer task.

  Attributes:
    base_options: Base options for the hand gesture recognizer task.
    running_mode: The running mode of the task. Default to the image mode.
      Gesture recognizer task has three running modes: 1) The image mode for
      recognizing hand gestures on single image inputs. 2) The video mode for
      recognizing hand gestures on the decoded frames of a video. 3) The live
      stream mode for recognizing hand gestures on a live stream of input data,
      such as from camera.
    num_hands: The maximum number of hands can be detected by the recognizer.
    min_hand_detection_confidence: The minimum confidence score for the hand
      detection to be considered successful.
    min_hand_presence_confidence: The minimum confidence score of hand presence
      score in the hand landmark detection.
    min_tracking_confidence: The minimum confidence score for the hand tracking
      to be considered successful.
    canned_gesture_classifier_options: Options for configuring the canned
      gestures classifier, such as score threshold, allow list and deny list of
      gestures. The categories for canned gesture classifiers are: ["None",
      "Closed_Fist", "Open_Palm", "Pointing_Up", "Thumb_Down", "Thumb_Up",
      "Victory", "ILoveYou"]. Note this option is subject to change.
    custom_gesture_classifier_options: Options for configuring the custom
      gestures classifier, such as score threshold, allow list and deny list of
      gestures. Note this option is subject to change.
    result_callback: The user-defined result callback for processing live stream
      data. The result callback should only be specified when the running mode
      is set to the live stream mode.
  r	   r   é   r   g      à?r   r   r   )Údefault_factoryÚ!canned_gesture_classifier_optionsÚ!custom_gesture_classifier_optionsNr   )r(   r)   r*   r+   Ú_BaseOptionsÚ__annotations__r4   ÚIMAGEr   r   r5   r   r6   r   r   ÚdataclassesÚfieldÚ_ClassifierOptionsrB   rC   r   r   r   ÚGestureRecognizerResultÚ	image_libÚImager7   r'   r%   r?   r?   ›   s¸   … ñð< ÓØ+×1Ñ1€,�Ó1Ø€)ˆSÓØ),Ð Ó,Ø(+Ð Ó+Ø#&Ð˜5Ó&Ø:K¸+×:KÑ:KØ(ô;Ð#Ð%7ó ð ;L¸+×:KÑ:KØ(ô;Ð#Ð%7ó ð
 ð �8ØÐ'¨¯©¸#Ð>ÀÐDÑEñô r'   r?   c            	       ó´  — e Zd ZU dZej
                  ed<   ej                  ed<   e	j                  ed<   eed<   dej
                  dej                  de	j                  d	efd
„Zededd fd„«       Zededd fd„«       Z	 ddej&                  dee   defd„Z	 ddej&                  dedee   defd„Z	 ddej&                  dedee   ddfd„Zd„ Zd„ Zd„ Zd„ Zy)ÚGestureRecognizerz2Class that performs gesture recognition on images.Ú_libÚ_handleÚ_dispatcherÚ_async_callbackÚlibÚhandleÚ
dispatcherÚasync_callbackc                 ó<   — || _         || _        || _        || _        y)a5  Initializes the gesture recognizer.

    Args:
      lib: The dispatch library to use for the gesture recognizer.
      handle: The C pointer to the gesture recognizer.
      dispatcher: The async result handler for the gesture recognizer.
      async_callback: The c callback for the gesture recognizer.
    N)rO   rP   rQ   rR   )ÚselfrS   rT   rU   rV   s        r%   Ú__init__zGestureRecognizer.__init__Ô   s"   € ð €D„IØ€D„LØ!€DÔØ)€DÕr'   Ú
model_pathr    c                 ór   — t        |¬«      }t        |t        j                  ¬«      }| j	                  |«      S )ai  Creates an `GestureRecognizer` object from a TensorFlow Lite model and the default `GestureRecognizerOptions`.

    Note that the created `GestureRecognizer` instance is in image mode, for
    recognizing hand gestures on single image inputs.

    Args:
      model_path: Path to the model.

    Returns:
      `GestureRecognizer` object that's created from the model file and the
      default `GestureRecognizerOptions`.

    Raises:
      ValueError: If failed to create `GestureRecognizer` object from the
        provided file such as invalid file path.
      RuntimeError: If other types of error occurred.
    )Úmodel_asset_path)r	   r   )rD   r?   r4   rF   Úcreate_from_options)r$   rZ   r	   Úoptionss       r%   Úcreate_from_model_pathz(GestureRecognizer.create_from_model_pathè   s6   € ô&  °Ô<€LÜ&Ø!´×0BÑ0Bô€Gð ×"Ñ" 7Ó+Ð+r'   r^   c                 ó¦  — t        j                  |j                  |j                  «       t	        j
                  t        «      }dt        j                  t        j                  «      dt        j                  dt        dt        t        t        j                   t        f   fd„}t#        j$                  |¬«      }|j'                  |j                  t(        «      }t*        j-                  |j.                  j1                  «       |j                  |j2                  |j4                  |j6                  |j8                  t;        j<                  |j>                  «      t;        j<                  |j@                  «      |¬«	      }t        j                  «       }|jC                  t        jD                  |«      t        jD                  |«      «        | ||||¬«      S )	a¤  Creates the `GestureRecognizer` object from gesture recognizer options.

    Args:
      options: Options for the gesture recognizer task.

    Returns:
      `GestureRecognizer` object that's created from `options`.

    Raises:
      ValueError: If failed to create `GestureRecognizer` object from
        `GestureRecognizerOptions` such as missing the model.
      RuntimeError: If other types of error occurred.
    Úc_result_ptrÚ	image_ptrÚtimestamp_msr    c                 ó~   — | d   }t         j                  |«      }t        j                  j	                  |«      }|||fS )Nr   )rJ   Úfrom_ctypesrK   rL   Úcreate_from_ctypes)ra   rb   rc   Úc_resultÚ	py_resultÚpy_images         r%   Úconvert_resultz=GestureRecognizer.create_from_options.<locals>.convert_result  s>   € ð ˜a‘€hÜ)×5Ñ5°hÓ?€iÜ—‘×3Ñ3°IÓ>€hØ˜ <Ð0Ð0r'   )Ú	converterr"   )rS   rT   rU   rV   )#Úrunning_mode_moduleÚvalidate_running_moder   r   r   Úload_shared_libraryÚ_CTYPES_SIGNATURESr-   ÚPOINTERr   ÚGestureRecognizerResultCÚc_void_pr5   r   rJ   rK   rL   r   ÚAsyncResultDispatcherÚwrap_callbackr   r   r&   r	   Ú	to_ctypesr   r   r   r   r   Úconvert_to_classifier_options_crB   rC   r8   Úbyref)r$   r^   rS   rj   rU   Ú
c_callbackÚ	options_cÚrecognizer_handles           r%   r]   z%GestureRecognizer.create_from_options  s˜  € ô" ×-Ñ-Ø×Ñ˜g×5Ñ5ôô ×
2Ñ
2Ô3EÓ
F€Cð
1Ü—n‘nÜ'×@Ñ@ó
ð
1ô —?‘?ð	
1ô
 ð
1ô 
Ô&¬	¯©¼Ð<Ñ	=ó
1ô )×>Ñ>Ø ô€Jð ×)Ñ)Ø×ÑÔ!9ó€Jô *×8Ñ8Ø×)Ñ)×3Ñ3Ó5Ø×)Ñ)Ø×#Ñ#Ø&-×&KÑ&KØ%,×%IÑ%IØ '× ?Ñ ?Ü+?×+_Ñ+_Ø×5Ñ5ó,
ô ,@×+_Ñ+_Ø×5Ñ5ó,
ð #ð 9ó €Iô Ÿ™Ó)ÐØ×!Ñ!Ü�‰�YÓÜ�‰Ð&Ó'ôñ ØØ ØØ!ô	ð r'   Nr   r   c                 ó�  — |j                   }t        j                  «       }|r#t        j                  |j                  «       «      nd}| j                  j                  | j                  ||t        j                  |«      «       t        j                  |«      }| j                  j                  t        j                  |«      «       |S )aa  Performs hand gesture recognition on the given image.

    Only use this method when the GestureRecognizer is created with the image
    running mode.

    The image can be of any size with format RGB or RGBA.
    TODO: Describes how the input image will be preprocessed after the yuv
    support is implemented.

    Args:
      image: MediaPipe Image.
      image_processing_options: Options for image processing.

    Returns:
      The hand gesture recognition results.

    Raises:
      ValueError: If any of the input arguments is invalid.
      RuntimeError: If gesture recognition failed to run.
    N)Ú
_image_ptrr   rq   r-   rw   ru   rO   r9   rP   rJ   re   r<   )rX   r   r   Úc_imagerg   ry   Úresults          r%   Ú	recognizezGestureRecognizer.recognizeE  s¡   € ð2 ×Ñ€GÜ*×CÑCÓE€Hñ $ô 	�‰Ð-×7Ñ7Ó9Ô:àð ð
 	‡I�I×/Ñ/Ø�‰ØØÜ�‰�XÓô	ô %×0Ñ0°Ó:€FØ‡I�I×,Ñ,¬V¯\©\¸(Ó-CÔDØ€Mr'   rc   c           	      ó’  — |j                   }t        j                  «       }|r#t        j                  |j                  «       «      nd}| j                  j                  | j                  |||t        j                  |«      «       t        j                  |«      }| j                  j                  t        j                  |«      «       |S )a6  Performs gesture recognition on the provided video frame.

    Only use this method when the GestureRecognizer is created with the video
    running mode.

    Only use this method when the GestureRecognizer is created with the video
    running mode. It's required to provide the video frame's timestamp (in
    milliseconds) along with the video frame. The input timestamps should be
    monotonically increasing for adjacent calls of this method.

    Args:
      image: MediaPipe Image.
      timestamp_ms: The timestamp of the input video frame in milliseconds.
      image_processing_options: Options for image processing.

    Returns:
      The hand gesture recognition results.

    Raises:
      ValueError: If any of the input arguments is invalid.
      RuntimeError: If gesture recognition failed to run.
    N)r|   r   rq   r-   rw   ru   rO   r:   rP   rJ   re   r<   )rX   r   rc   r   r}   rg   ry   r~   s           r%   Úrecognize_for_videoz%GestureRecognizer.recognize_for_videop  s¤   € ð8 ×Ñ€GÜ*×CÑCÓE€Hñ $ô 	�‰Ð-×7Ñ7Ó9Ô:àð ð
 	‡I�I×2Ñ2Ø�‰ØØØÜ�‰�XÓôô %×0Ñ0°Ó:€FØ‡I�I×,Ñ,¬V¯\©\¸(Ó-CÔDØ€Mr'   c                 óº   — |j                   }|r#t        j                  |j                  «       «      nd}| j                  j                  | j                  |||«       y)av  Sends live image data to perform gesture recognition.

    The results will be available via the "result_callback" provided in the
    GestureRecognizerOptions. Only use this method when the GestureRecognizer
    is created with the live stream running mode.

    Only use this method when the GestureRecognizer is created with the live
    stream running mode. The input timestamps should be monotonically increasing
    for adjacent calls of this method. This method will return immediately after
    the input image is accepted. The results will be available via the
    `result_callback` provided in the `GestureRecognizerOptions`. The
    `recognize_async` method is designed to process live stream data such as
    camera input. To lower the overall latency, gesture recognizer may drop the
    input images if needed. In other words, it's not guaranteed to have output
    per input image.

    The `result_callback` provides:
      - The hand gesture recognition results.
      - The input image that the gesture recognizer runs on.
      - The input timestamp in milliseconds.

    Args:
      image: MediaPipe Image.
      timestamp_ms: The timestamp of the input image in milliseconds.
      image_processing_options: Options for image processing.

    Raises:
      ValueError: If the current input timestamp is smaller than what the
      gesture recognizer has already processed.
    N)r|   r-   rw   ru   rO   r;   rP   )rX   r   rc   r   r}   ry   s         r%   Úrecognize_asyncz!GestureRecognizer.recognize_asyncŸ  sY   € ðH ×Ñ€Gñ $ô 	�‰Ð-×7Ñ7Ó9Ô:àð ð
 	‡I�I×/Ñ/Ø�‰ØØØõ	r'   c                 óÞ   — | j                   sy| j                  j                  | j                   «       d| _         | j                  j	                  «        | j                  j	                  «        y)zCloses GestureRecognizer.N)rP   rO   r=   rQ   Úclose©rX   s    r%   r…   zGestureRecognizer.closeÐ  sI   € à�<Š<ØØ‡I�I×&Ñ& t§|¡|Ô4Ø€D„LØ×Ñ×ÑÔØ‡I�I‡O�OÕr'   c                 ó   — | S )z1Returns `self` upon entering the runtime context.r7   r†   s    r%   Ú	__enter__zGestureRecognizer.__enter__Ù  s   € à€Kr'   c                 ó$   — | j                  «        y)a�  Closes GestureRecognizers and exits the context manager.

    Args:
      exc_type: The exception type that caused the context manager to exit.
      exc_value: The exception value that caused the context manager to exit.
      traceback: The exception traceback that caused the context manager to
        exit.

    Raises:
      RuntimeError: If the MediaPipe Gesture Recognizer task failed to
      close.
    N©r…   )rX   Úexc_typeÚ	exc_valueÚ	tracebacks       r%   Ú__exit__zGestureRecognizer.__exit__Ý  s   € ð 	‡J�J…Lr'   c                 ó$   — | j                  «        y ©NrŠ   r†   s    r%   Ú__del__zGestureRecognizer.__del__ì  s   € Ø‡J�J…Lr'   r�   )r(   r)   r*   r+   r   ÚSerialDispatcherrE   r-   rr   r   rs   r   rY   r2   Ústrr_   r?   r]   rK   rL   r   Ú_ImageProcessingOptionsrJ   r   r5   r�   rƒ   r…   rˆ   rŽ   r‘   r7   r'   r%   rN   rN   Ì   su  … Ù:à×*Ñ*Ó*Ø�?‰?ÓØ&×<Ñ<Ó<Ø+Ó+ð*à×-Ñ-ð*ð �o‰oð*ð *×?Ñ?ð	*ð
 /ó*ð( ð,¨cð ,Ð6Iò ,ó ð,ð0 ðAØ,ðAàòAó ðAðL EIñ)à�_‰_ð)ð !)Ð)@Ñ Að)ð ó	)ð^ EIñ	-à�_‰_ð-ð ð-ð !)Ð)@Ñ Að	-ð
 ó-ðf EIñ	/à�_‰_ð/ð ð/ð !)Ð)@Ñ Að	/ð
 ó/òbòòór'   rN   )9r+   r-   rG   Útypingr   r   r   Ú,mediapipe.tasks.python.components.processorsr   r   Úmediapipe.tasks.python.corer   r	   Úbase_options_moduler
   r   r   r   Ú1mediapipe.tasks.python.core.optional_dependenciesr   Úmediapipe.tasks.python.visionr   Ú gesture_recognizer_result_moduler   Ú"mediapipe.tasks.python.vision.corer   rK   r   Úimage_processing_options_libr   r   rl   ÚBaseOptionsrD   ÚClassifierOptionsrI   ÚVisionTaskRunningModer4   ÚImageProcessingOptionsr”   rJ   Ú	CFUNCTYPEÚc_int32rp   rq   rr   Úc_int64r   Ú	Structurer   ÚCStatusFunctionÚImageProcessingOptionsCÚ	CFunctionro   Ú	dataclassr?   rN   r7   r'   r%   ú<module>rª      s�  ðñ )ã Û ß ,Ñ ,å KÝ MÝ ?Ý KÝ 6Ý <Ý 9Ý 9Ý JÝ gå EÝ AÝ gÝ IÝ ^à"×.Ñ.€Ø'×9Ñ9Ð Ø"×8Ñ8€Ø6×MÑMÐ à$×<Ñ<ð ð
 ,˜6×+Ñ+ØØ
‡N�NØ€F‡N�NÐ.×GÑGÓHØ
‡O�OØ
‡N�NóÐ ô- × 0Ñ 0ô -ðb &Ð×%Ñ%Ø#àˆF�N‰NÐ4Ó5ØˆF�N‰N˜6Ÿ?™?Ó+ð	
óð &Ð×%Ñ%Ø+à�O‰OØ�O‰OØˆF�N‰NÐ5×MÑMÓNØˆF�N‰NØ+×DÑDóð		
ó
ð &Ð×%Ñ%Ø.à�O‰OØ�O‰OØˆF�N‰NÐ5×MÑMÓNØ�N‰NØˆF�N‰NØ+×DÑDóð	
óð &Ð×%Ñ%Ø+à�O‰OØ�O‰OØˆF�N‰NÐ5×MÑMÓNØ�N‰Nð		
óð  Ð×ÑØ(Ø	ˆ�‰Ð3×LÑLÓ	MÐNØóð
 &Ð×%Ñ%Ø"Ø	�‰Ðóð[1Ð ðh ×Ñ÷-ð -ó ð-÷`aò ar'   