
    Wpf                     V   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 ej!        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 aligner 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face_alignmentFACE_ALIGNMENTnorm_rect_in	NORM_RECTimage_in	image_outIMAGEz6mediapipe.tasks.vision.face_stylizer.FaceStylizerGraphc                   D    e Zd ZU dZeed<   ej        defd            Z	dS )FaceAlignerOptionsznOptions for the face aligner task.

  Attributes:
    base_options: Base options for the face aligner task.
  r	   returnc                 b    | j                                         }d|_        t          |          S )z0Generates a FaceStylizerOptions protobuf object.Fr   )r	   to_pb2use_stream_mode_FaceStylizerGraphOptionsProto)selfbase_options_protos     j/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/mediapipe/tasks/python/vision/face_aligner.pyr   zFaceAlignerOptions.to_pb2:   s4     *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 )FaceAlignerz-Class that performs face alignment on images.
model_pathr   c                 l    t          |          }t          |          }|                     |          S )aY  Creates a `FaceAligner` object from a face landmarker task bundle and the default `FaceAlignerOptions`.

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

    Args:
      model_path: Path to the face landmarker task bundle.

    Returns:
      `FaceAligner` object that's created from the model file and the default
      `FaceAlignerOptions`.

    Raises:
      ValueError: If failed to create `FaceAligner` 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"FaceAligner.create_from_model_pathE   s8    &  <<<L l;;;G""7+++r    r0   c           	         t          t          d                    t          t          g          d                    t
          t          g          gd                    t          t          g          d                    t          t          g          g|          } | |
                    d          t          j        d          S )a  Creates the `FaceAligner` object from face aligner options.

    Args:
      options: Options for the face aligner task.

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

    Raises:
      ValueError: If failed to create `FaceAligner` object from
        `FaceAlignerOptions` such as missing the model.
      RuntimeError: If other types of error occurred.
    :)
task_graphinput_streamsoutput_streamstask_optionsF)enable_flow_limitingN)	_TaskInfo_TASK_GRAPH_NAMEjoin
_IMAGE_TAG_IMAGE_IN_STREAM_NAME_NORM_RECT_TAG_NORM_RECT_STREAM_NAME_FACE_ALIGNMENT_IMAGE_TAG_FACE_ALIGNMENT_IMAGE_NAME_IMAGE_OUT_STREAM_NAMEgenerate_graph_config_RunningModer   )r/   r0   r
   s      r   r.   zFaceAligner.create_from_options\   s     #HHj"7899HHn&<=>>

 HH/1KLMMHHj"89::
   I 3''U'CC  r    Nr   r   c           	      `   |                      ||          }|                     t          t          j        |          t
          t          j        |                                          i          }|t                   	                                rdS t          j        |t                             S )a#  Performs face alignment on the provided MediaPipe Image.

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

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

    Returns:
      The aligned face image. The aligned 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 alignment failed to run.
    N)convert_to_normalized_rect_process_image_datar=   r   create_imager?   create_protor   rA   is_emptyr   	get_image)r   r   r   normalized_rectoutput_packetss        r   alignzFaceAligner.align}   s    , 55 % O --~:5AA ;""$$!
 !
/  N 01::<< T">2L#MNNNr    )N)r!   r"   r#   r$   classmethodstrr1   r   r.   image_moduleImager   _ImageProcessingOptionsrN   r(   r    r   r*   r*   B   s        55,c ,m , , , ;,, (: }    ;F EI!O !O!O !))@ A!O 	!O !O !O !O !O !O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   running_mode_moduleBaseOptionsr%   FaceStylizerGraphOptionsr   VisionTaskRunningModerD   ImageProcessingOptionsrS   TaskInfor9   rA   r@   r?   r>   r=   rB   r<   r:   	dataclassr   BaseVisionTaskApir*   r(   r    r   <module>rg      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 ^ ^ ^ ^ ^ ^".#<  #89P %	- , ' " $ 
K  K K K K K K K K"\O \O \O \O \O&8 \O \O \O \O \Or    