Ë
    »dæj¸/  ã                   ó  — d Z ddlZddlZddlZddl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 ej@                  Z!ejD                  Z#ejH                  Z%ejL                  Z' G d„ dejP                  «      Z) G d„ dejP                  «      Z* ejV                  d ejX                  e*«       ejX                  ejZ                  «      f«       ejV                  dejZ                  ejZ                   ejX                  e)«       ejX                  ej\                  «       ejX                  ej^                  «      f«       ejH                  d ejX                  ej^                  «      gd«       ejV                  dejZ                  f«      fZ0ejb                   G d„ d«      «       Z2ejb                   G d„ d«      «       Z3ejb                   G d„ d«      «       Z4 G d„ d «      Z5y)!z%MediaPipe interactive segmenter task.é    N)ÚListÚOptional)Úkeypoint)Ú
keypoint_c)Úasync_result_dispatcher©Úbase_options)Úbase_options_c)Úmediapipe_c_bindings)Úmediapipe_c_utils)Úserial_dispatcher)Údoc_controls)Úimage_segmenter)Úimage)Úimage_processing_options)Úimage_processing_options_cc                   óæ   — e Zd ZdZ G d„ dej
                  «      Zdej                  fd ej                  e
j                  «      fd ej                  e
j                  «      fdej                  fgZy)	ÚRegionOfInterestCú.The Region-Of-Interest (ROI) to interact with.c                   ó   — e Zd ZdZdZdZy)úRegionOfInterestC.Formatr   é   é   N)Ú__name__Ú
__module__Ú__qualname__ÚUNSPECIFIEDÚKEYPOINTÚSCRIBBLE© ó    úv/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/mediapipe/tasks/python/vision/interactive_segmenter.pyÚFormatr   ,   s   „ Ø€KØ€HØ�Hr!   r#   Úformatr   ÚscribbleÚscribble_countN)r   r   r   Ú__doc__ÚenumÚIntEnumr#   ÚctypesÚc_intÚPOINTERÚkeypoint_c_moduleÚNormalizedKeypointCÚc_uint32Ú_fields_r    r!   r"   r   r   )   sj   „ Ù6ôˆt�|‰|ô ð �—‘ÐØ�>�6—>‘>Ð"3×"GÑ"GÓHÐIØ�>�6—>‘>Ð"3×"GÑ"GÓHÐIØ˜Ÿ™Ð)ð	�(r!   r   c                   ób   — e Zd ZdZdej
                  fdej                  fdej                  fgZy)ÚInteractiveSegmenterOptionsCz>The MediaPipe Tasks InteractiveSegmenterOptions CTypes struct.r	   Úoutput_confidence_masksÚoutput_category_maskN)	r   r   r   r'   Úbase_options_c_moduleÚBaseOptionsCr*   Úc_boolr0   r    r!   r"   r2   r2   9   s5   „ ÙFð Ð,×9Ñ9Ð:Ø  &§-¡-Ð0Ø˜vŸ}™}Ð-ð�(r!   r2   ÚMpInteractiveSegmenterCreateÚ"MpInteractiveSegmenterSegmentImageÚ!MpInteractiveSegmenterCloseResultÚMpInteractiveSegmenterClosec                   ó´   — e Zd ZU dZdZeeej                        e	d<   dZ
eej                     e	d<   eej                  dej                  dd fd„«       «       Zy)ÚInteractiveSegmenterResulta]  Output result of InteractiveSegmenter.

  confidence_masks: multiple masks of float image where, for each mask, each
  pixel represents the prediction confidence, usually in the [0, 1] range.

  category_mask: a category mask of uint8 image where each pixel represents the
  class which the pixel in the original image was predicted to belong to.
  NÚconfidence_masksÚcategory_maskÚc_resultÚreturnc                 ó|   — t         j                  j                  |«      } | |j                  |j                  ¬«      S )zIConverts a C ImageSegmenterResult to a Python InteractiveSegmenterResult.)r>   r?   )r   ÚImageSegmenterResultÚfrom_ctypesr>   r?   )Úclsr@   Úbase_results      r"   rD   z&InteractiveSegmenterResult.from_ctypesq   s9   € ô "×6Ñ6×BÑBÀ8ÓL€KÙØ$×5Ñ5Ø!×/Ñ/ôð r!   )r   r   r   r'   r>   r   r   Úimage_moduleÚImageÚ__annotations__r?   Úclassmethodr   Údo_not_generate_docsr   ÚImageSegmenterResultCrD   r    r!   r"   r=   r=   c   so   … ñð :>Ð�H˜T ,×"4Ñ"4Ñ5Ñ6Ó=Ø04€-�˜,×,Ñ,Ñ-Ó4àØ×$Ñ$ðØ$×:Ñ:ðà#òó %ó ñr!   r=   c                   ób   — e Zd ZU dZeed<   dZeed<   dZeed<   e	j                  defd„«       Zy	)
ÚInteractiveSegmenterOptionsaœ  Options for the interactive segmenter task.

  Attributes:
    base_options: Base options for the interactive segmenter task.
    running_mode: The running mode of the task.
    output_confidence_masks: Whether to output confidence masks.
    output_category_mask: Whether to output category mask.
    result_callback: The callback function that is invoked synchronously when
      the current thread is idle.
  r	   Tr3   Fr4   rA   c                 óv   — t        | j                  j                  «       | j                  | j                  ¬«      S )z8Generates an InteractiveSegmenterOptionsC ctypes struct.)r	   r3   r4   )r2   r	   Ú	to_ctypesr3   r4   ©Úselfs    r"   rP   z%InteractiveSegmenterOptions.to_ctypes�   s5   € ô (Ø×&Ñ&×0Ñ0Ó2Ø $× <Ñ <Ø!×6Ñ6ôð r!   N)r   r   r   r'   Ú_BaseOptionsrI   r3   Úboolr4   r   rK   r2   rP   r    r!   r"   rN   rN   ~   sE   … ñ	ð ÓØ"&Ð˜4Ó&Ø$Ð˜Ó$à×$Ñ$ðÐ5ò ó %ñr!   rN   c                   ó˜   — e Zd ZU dZ G d„ dej
                  «      Zeed<   dZe	e
j                     ed<   ej                  defd„«       Zy)	ÚRegionOfInterestr   c                   ó   — e Zd ZdZdZy)úRegionOfInterest.Formatr   r   N)r   r   r   r   r   r    r!   r"   r#   rX   �   s   „ Ø€KØ�Hr!   r#   r$   Nr   rA   c                 óî  — | j                   �ß| j                  t        j                  j                  k(  rt        d«      ‚| j                  t        j                  j                  k(  r{t        | j                  j                  ¬«      }t        j                  | j                   j                  | j                   j                  ¬«      }t        j                  |«      |_         |S t        d«      ‚t        d«      ‚)z<Converts a Python RegionOfInterest to a C RegionOfInterestC.z&RegionOfInterest format not specified.)r$   )ÚxÚyz7Please specify the Region-of-interest for segmentation.zUnrecognized format.)r   r$   rV   r#   r   Ú
ValueErrorr   r   Úvaluer-   r.   rZ   r[   r*   Úpointer)rR   Úc_roiÚ
c_keypoints      r"   rP   zRegionOfInterest.to_ctypes¤   sº   € ð ‡}�}Ð Ø	�‰Ô(×/Ñ/×;Ñ;Ò	;ÜÐAÓBÐBØ�;‰;Ô*×1Ñ1×:Ñ:Ò:Ü!¨¯©×):Ñ):Ô;ˆÜ&×:Ñ:Ø�m‰m�o‰o §¡§¡ô
ˆ
ô  Ÿ™¨
Ó3ˆŒØˆäØEó
ð 	
ô Ð+Ó
,Ð,r!   )r   r   r   r'   r(   ÚEnumr#   rI   r   r   Úkeypoint_moduleÚNormalizedKeypointr   rK   r   rP   r    r!   r"   rV   rV   ™   sQ   … á6ôˆt�y‰yô ð ƒ.Ø;?€(ˆH�_×7Ñ7Ñ8Ó?à×$Ñ$ð-Ð*ò -ó %ñ-r!   rV   c            	       ó>  — e Zd ZU dZej
                  ed<   ej                  ed<   e	j                  ed<   dej
                  dej                  de	j                  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dee   d
efd„Zd„ Zd„ Zd„ Zd„ Zy)ÚInteractiveSegmenteraK  Class that performs interactive segmentation on images.

  Users can represent user interaction through `RegionOfInterest`, which gives
  a hint to InteractiveSegmenter to perform segmentation focusing on the given
  region of interest.

  The API expects a TFLite model with mandatory TFLite Model Metadata.

  Input tensor:
    (kTfLiteUInt8/kTfLiteFloat32)
    - image input of size `[batch x height x width x channels]`.
    - batch inference is not supported (`batch` is required to be 1).
    - RGB and greyscale inputs are supported (`channels` is required to be
      1 or 3).
    - if type is kTfLiteFloat32, NormalizationOptions are required to be
      attached to the metadata for input normalization.
  Output tensors:
    (kTfLiteUInt8/kTfLiteFloat32)
    - list of segmented masks.
    - if `output_type` is CATEGORY_MASK, uint8 Image, Image vector of size 1.
    - if `output_type` is CONFIDENCE_MASK, float32 Image list of size
      `channels`.
    - batch is always 1

  An example of such model can be found at:
  https://tfhub.dev/tensorflow/lite-model/deeplabv3/1/metadata/2
  Ú_libÚ_handleÚ_dispatcherÚlibÚhandleÚ
dispatcherc                 ó.   — || _         || _        || _        y)z.Initializes the `InteractiveSegmenter` object.N)rf   rg   rh   )rR   ri   rj   rk   s       r"   Ú__init__zInteractiveSegmenter.__init__Ú   s   € ð €D„IØ€D„LØ!€DÕr!   Ú
model_pathrA   c                 óT   — t        |¬«      }t        |¬«      }| j                  |«      S )a  Creates an `InteractiveSegmenter` object from a TensorFlow Lite model and the default `InteractiveSegmenterOptions`.

    Note that the created `InteractiveSegmenter` instance is in image mode, for
    performing image segmentation on single image inputs.

    Args:
      model_path: Path to the model.

    Returns:
      `InteractiveSegmenter` object that's created from the model file and the
      default `InteractiveSegmenterOptions`.

    Raises:
      ValueError: If failed to create `InteractiveSegmenter` object from the
        provided file such as invalid file path.
      RuntimeError: If other types of error occurred.
    )Úmodel_asset_pathr   )rS   rN   Úcreate_from_options)rE   rn   r	   Úoptionss       r"   Úcreate_from_model_pathz+InteractiveSegmenter.create_from_model_pathå   s)   € ô&  °Ô<€LÜ)°|ÔD€GØ×"Ñ" 7Ó+Ð+r!   rr   c                 ó  — t        j                  t        «      }t        d„ ¬«      }|j	                  «       }t        j                  «       }|j                  t        j                  |«      t        j                  |«      «        | |||«      S )a¶  Creates the `InteractiveSegmenter` object from interactive segmenter options.

    Args:
      options: Options for the interactive segmenter task.

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

    Raises:
      ValueError: If failed to create `InteractiveSegmenter` object from
        `InteractiveSegmenterOptions` such as missing the model.
      RuntimeError: If other types of error occurred.
    c                 ó   — | S ©Nr    )rZ   s    r"   ú<lambda>z:InteractiveSegmenter.create_from_options.<locals>.<lambda>  s   € ¸A€ r!   )Ú	converter)	r   Úload_shared_libraryÚ_CTYPES_SIGNATURESÚ_AsyncResultDispatcherrP   r*   Úc_void_pr8   Úbyref)rE   rr   ri   rk   Úctypes_optionsÚsegmenter_handles         r"   rq   z(InteractiveSegmenter.create_from_optionsü   sr   € ô" ×
2Ñ
2Ô3EÓ
F€CÜ'±+Ô>€JØ×&Ñ&Ó(€Nä—‘Ó(ÐØ×$Ñ$Ü�‰�^Ó$¤f§l¡lÐ3CÓ&Dôñ ˆsÐ$ jÓ1Ð1r!   Nr   Úroir   c           	      óØ  — |j                   }|j                  «       }t        j                  «       }|r#t	        j
                  |j                  «       «      nd}| j                  j                  | j                  |t	        j
                  |«      |t	        j
                  |«      «       t        j                  |«      }| j                  j                  t	        j
                  |«      «       |S )a  Performs the actual segmentation task on the provided MediaPipe Image.

    The image can be of any size with format RGB.

    Args:
      image: MediaPipe Image.
      roi: Optional user-specified region of interest for segmentation.
      image_processing_options: Options for image processing.

    Returns:
      If the output_type is CATEGORY_MASK, the returned vector of images is
      per-category segmented image mask.
      If the output_type is CONFIDENCE_MASK, the returned vector of images
      contains only one confidence image mask. A segmentation result object that
      contains a list of segmentation masks as images.

    Raises:
      ValueError: If any of the input arguments is invalid.
      RuntimeError: If image segmentation failed to run.
    N)Ú
_image_ptrrP   r   rL   r*   r}   rf   r9   rg   r=   rD   r:   )	rR   r   r€   r   Úc_imager_   r@   Ú	options_cÚ	py_results	            r"   ÚsegmentzInteractiveSegmenter.segment  s¹   € ð4 ×Ñ€GØ�M‰M‹O€EÜ×4Ñ4Ó6€Hñ $ô 	�‰Ð-×7Ñ7Ó9Ô:àð ð
 	‡I�I×0Ñ0Ø�‰ØÜ�‰�UÓØÜ�‰�XÓôô +×6Ñ6°xÓ@€IØ‡I�I×/Ñ/´·±¸XÓ0FÔGØÐr!   c                 óÞ   — | j                   sy| j                  j                  | j                   «       d| _         | j                  j	                  «        | j                  j	                  «        y)z Closes the InteractiveSegmenter.N)rg   rf   r;   rh   ÚcloserQ   s    r"   rˆ   zInteractiveSegmenter.closeE  sI   € à�<Š<ØØ‡I�I×)Ñ)¨$¯,©,Ô7Ø€D„LØ×Ñ×ÑÔØ‡I�I‡O�OÕr!   c                 ó   — | S )z1Returns `self` upon entering the runtime context.r    rQ   s    r"   Ú	__enter__zInteractiveSegmenter.__enter__N  s   € à€Kr!   c                 ó*   — ~~~| j                  «        y)zFShuts down the MediaPipe task instance on exit of the context manager.N©rˆ   )rR   Úexc_typeÚ	exc_valueÚ	tracebacks       r"   Ú__exit__zInteractiveSegmenter.__exit__R  s   € à�)˜YØ‡J�J…Lr!   c                 ó$   — | j                  «        y rv   rŒ   rQ   s    r"   Ú__del__zInteractiveSegmenter.__del__W  s   € Ø‡J�J…Lr!   rv   )r   r   r   r'   r   ÚSerialDispatcherrI   r*   r|   r   ÚAsyncResultDispatcherrm   rJ   Ústrrs   rN   rq   rG   rH   rV   r   Ú_ImageProcessingOptionsr=   r†   rˆ   rŠ   r�   r’   r    r!   r"   re   re   ¹   sö   … ñð8 	×*Ñ*Ó*Ø�?‰?ÓØ&×<Ñ<Ó<ð	"à×-Ñ-ð	"ð �o‰oð	"ð *×?Ñ?ó		"ð ð,¨cð ,Ð6Lò ,ó ð,ð, ð2Ø/ð2àò2ó ð2ð< EIñ	,à×Ñð,ð ð,ð !)Ð)@Ñ Að	,ð
 "ó,ò\òòó
r!   re   )6r'   r*   Údataclassesr(   Útypingr   r   Ú,mediapipe.tasks.python.components.containersr   rb   r   r-   Úmediapipe.tasks.python.corer   r	   Úbase_options_moduler
   r5   r   r   r   Ú1mediapipe.tasks.python.core.optional_dependenciesr   Úmediapipe.tasks.python.visionr   Ú"mediapipe.tasks.python.vision.corer   rG   r   Úimage_processing_options_moduler   Ú!image_processing_options_c_moduleÚBaseOptionsrS   ÚImageProcessingOptionsr–   Ú	CFunctionÚ
_CFunctionr”   r{   Ú	Structurer   r2   ÚCStatusFunctionr,   r|   ÚImageProcessingOptionsCrL   rz   Ú	dataclassr=   rN   rV   re   r    r!   r"   ú<module>r©      sò  ðñ ,ã Û Û ß !å TÝ XÝ ?Ý KÝ OÝ <Ý 9Ý 9Ý JÝ 9Ý DÝ jÝ nà"×.Ñ.€Ø9×PÑPÐ Ø×(Ñ(€
Ø0×FÑFÐ ô˜×(Ñ(ô ô  6×#3Ñ#3ô ð &Ð×%Ñ%Ø&àˆF�N‰NÐ7Ó8ØˆF�N‰N˜6Ÿ?™?Ó+ð	
óð &Ð×%Ñ%Ø,à�O‰OØ�O‰OØˆF�N‰NÐ,Ó-ØˆF�N‰NØ1×IÑIóð ˆF�N‰N˜?×@Ñ@ÓAð	
óð  Ð×ÑØ+Ø	ˆ�‰˜×=Ñ=Ó	>Ð?Øóð
 &Ð×%Ñ%Ø%Ø	�‰Ðóð3Ð ð@ ×Ñ÷ð ó ðð4 ×Ñ÷ð ó ðð4 ×Ñ÷-ð -ó ð-÷>_ò _r!   