
    Wpf                     L   d Z ddl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j        Zej        Zej        Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)ej*         G d d                      Z+ G d dej,                  Z-dS )zMediaPipe face stylizer task.    N)Optional)packet_creator)packet_getter)image)face_stylizer_graph_options_pb2base_options)	task_info)doc_controls)base_vision_task_api)image_processing_options)vision_task_running_modestylized_imageSTYLIZED_IMAGEnorm_rect_in	NORM_RECTimage_in	image_outIMAGEz6mediapipe.tasks.vision.face_stylizer.FaceStylizerGraphi  c                   D    e Zd ZU dZeed<   ej        defd            Z	dS )FaceStylizerOptionszpOptions for the face stylizer task.

  Attributes:
    base_options: Base options for the face stylizer task.
  r	   returnc                 T    | j                                         }t          |          S )z1Generates an FaceStylizerOptions protobuf object.r   )r	   to_pb2_FaceStylizerGraphOptionsProto)selfbase_options_protos     k/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/mediapipe/tasks/python/vision/face_stylizer.pyr   zFaceStylizerOptions.to_pb2:   s+     *1133)7IJJJJ    N)
__name__
__module____qualname____doc___BaseOptions__annotations__r   do_not_generate_docsr   r    r   r   r   r   0   s_           $K4 K K K %$K K Kr   r   c                       e Zd Z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	j
        fd
ZdS )FaceStylizerz/Class that performs face stylization on images.
model_pathr   c                 l    t          |          }t          |          }|                     |          S )aE  Creates an `FaceStylizer` object from a TensorFlow Lite model and the default `FaceStylizerOptions`.

    Note that the created `FaceStylizer` instance is in image mode, for
    stylizing one face on a single image input.

    Args:
      model_path: Path to the model.

    Returns:
      `FaceStylizer` object that's created from the model file and the default
      `FaceStylizerOptions`.

    Raises:
      ValueError: If failed to create `FaceStylizer` object from the provided
        file such as invalid file path.
      RuntimeError: If other types of error occurred.
    )model_asset_pathr   )r$   r   create_from_options)clsr*   r	   optionss       r   create_from_model_pathz#FaceStylizer.create_from_model_pathD   s8    &  <<<L!|<<<G""7+++r   r/   c           	         t          t          d                    t          t          g          d                    t
          t          g          gd                    t          t          g          d                    t          t          g          g|          } | |
                                t          j        j                  S )a  Creates the `FaceStylizer` object from face stylizer options.

    Args:
      options: Options for the face stylizer task.

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

    Raises:
      ValueError: If failed to create `FaceStylizer` object from
        `FaceStylizerOptions` such as missing the model.
      RuntimeError: If other types of error occurred.
    :)
task_graphinput_streamsoutput_streamstask_options)running_mode)	_TaskInfo_TASK_GRAPH_NAMEjoin
_IMAGE_TAG_IMAGE_IN_STREAM_NAME_NORM_RECT_TAG_NORM_RECT_STREAM_NAME_STYLIZED_IMAGE_TAG_STYLIZED_IMAGE_NAME_IMAGE_OUT_STREAM_NAMEgenerate_graph_configrunning_mode_moduleVisionTaskRunningModer   )r.   r/   r
   s      r   r-   z FaceStylizer.create_from_options[   s      #HHj"7899HHn&<=>>

 HH)+?@AAHHj"89::
   I 3''))(>D   r   Nr   r   c           	      `   |                      ||          }|                     t          t          j        |          t
          t          j        |                                          i          }|t                   	                                rdS t          j        |t                             S )aD  Performs face stylization on the provided MediaPipe Image.

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

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

    Returns:
      The stylized image of the most visible face. The stylized output image
      size is the same as the model output size. None if no face is detected
      on the input image.

    Raises:
      ValueError: If any of the input arguments is invalid.
      RuntimeError: If face stylization failed to run.
    N)convert_to_normalized_rect_process_image_datar<   r   create_imager>   create_protor   r@   is_emptyr   	get_image)r   r   r   normalized_rectoutput_packetss        r   stylizezFaceStylizer.stylize|   s    . 55 % O --~:5AA ;""$$!
 !
/  N *+4466 T">2F#GHHHr   )N)r    r!   r"   r#   classmethodstrr0   r   r-   image_moduleImager   _ImageProcessingOptionsrN   r'   r   r   r)   r)   A   s        77,c ,n , , , ;,, (;     ;F EI"I "I"I !))@ A"I 	"I "I "I "I "I "Ir   r)   ).r#   dataclassestypingr   mediapipe.pythonr   r   $mediapipe.python._framework_bindingsr   rQ   -mediapipe.tasks.cc.vision.face_stylizer.protor   mediapipe.tasks.python.corer	   base_options_moduler
   task_info_module1mediapipe.tasks.python.core.optional_dependenciesr   "mediapipe.tasks.python.vision.corer   r   image_processing_options_moduler   rC   BaseOptionsr$   FaceStylizerGraphOptionsr   ImageProcessingOptionsrS   TaskInfor8   r@   r?   r>   r=   r<   rA   r;   r9   _MICRO_SECONDS_PER_MILLISECOND	dataclassr   BaseVisionTaskApir)   r'   r   r   <module>rf      s   $ #           + + + + + + * * * * * * F F F F F F Y Y Y Y Y Y K K K K K K E E E E E E J J J J J J C C C C C C j j j j j j ^ ^ ^ ^ ^ ^".#<  :P %	' & ' " $ 
K !%  K K K K K K K K ]I ]I ]I ]I ]I'9 ]I ]I ]I ]I ]Ir   