
    uki                        d Z ddlZddlm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 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%  G d dejL                        Z'dZ(d Z) G d d e!      Z*y)!zMediaPipe Pose.    N)
NamedTuple)#constant_side_packet_calculator_pb2)gate_calculator_pb2)split_vector_calculator_pb2)warp_affine_calculator_pb2)image_to_tensor_calculator_pb2)inference_calculator_pb2)(tensors_to_classification_calculator_pb2)$tensors_to_detections_calculator_pb2)#tensors_to_landmarks_calculator_pb2)&tensors_to_segmentation_calculator_pb2)ssd_anchors_calculator_pb2)"detections_to_rects_calculator_pb2)"landmarks_smoothing_calculator_pb2)"local_file_contents_calculator_pb2)logic_calculator_pb2)"non_max_suppression_calculator_pb2)"rect_transformation_calculator_pb2)thresholding_calculator_pb2)#visibility_smoothing_calculator_pb2)switch_container_pb2)SolutionBase)download_utils)POSE_CONNECTIONSc                       e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$y#)$PoseLandmarkzThe 33 pose landmarks.r                           	   
                                                                      N)%__name__
__module____qualname____doc__NOSELEFT_EYE_INNERLEFT_EYELEFT_EYE_OUTERRIGHT_EYE_INNER	RIGHT_EYERIGHT_EYE_OUTERLEFT_EAR	RIGHT_EAR
MOUTH_LEFTMOUTH_RIGHTLEFT_SHOULDERRIGHT_SHOULDER
LEFT_ELBOWRIGHT_ELBOW
LEFT_WRISTRIGHT_WRIST
LEFT_PINKYRIGHT_PINKY
LEFT_INDEXRIGHT_INDEX
LEFT_THUMBRIGHT_THUMBLEFT_HIP	RIGHT_HIP	LEFT_KNEE
RIGHT_KNEE
LEFT_ANKLERIGHT_ANKLE	LEFT_HEEL
RIGHT_HEELLEFT_FOOT_INDEXRIGHT_FOOT_INDEX     Z/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/mediapipe/python/solutions/pose.pyr   r   5   s    	
$.(./)/()*+-.*+*+*+*+*+())**+)*/rc   r   z:mediapipe/modules/pose_landmark/pose_landmark_cpu.binarypbc                 p    | dk(  rt        j                  d       y| dk(  rt        j                  d       yy)zoDownloads the pose landmark lite/heavy model from the MediaPipe Github repo if it doesn't exist in the package.r   z9mediapipe/modules/pose_landmark/pose_landmark_lite.tfliter   z:mediapipe/modules/pose_landmark/pose_landmark_heavy.tfliteN)r   download_oss_model)model_complexitys    rd   !_download_oss_pose_landmark_modelrh   ]   s=     %%CE1%%DF rc   c                   Z     e Zd ZdZ	 	 	 	 	 	 	 d fd	Zdej                  def fdZ xZ	S )PosezMediaPipe Pose.

  MediaPipe Pose processes an RGB image and returns pose landmarks on the most
  prominent person detected.

  Please refer to https://solutions.mediapipe.dev/pose#python-solution-api for
  usage examples.
  c           	      v    t        |       t        | 	  t        ||xr | ||xr | | d||dg d       y)aj  Initializes a MediaPipe Pose object.

    Args:
      static_image_mode: Whether to treat the input images as a batch of static
        and possibly unrelated images, or a video stream. See details in
        https://solutions.mediapipe.dev/pose#static_image_mode.
      model_complexity: Complexity of the pose landmark model: 0, 1 or 2. See
        details in https://solutions.mediapipe.dev/pose#model_complexity.
      smooth_landmarks: Whether to filter landmarks across different input
        images to reduce jitter. See details in
        https://solutions.mediapipe.dev/pose#smooth_landmarks.
      enable_segmentation: Whether to predict segmentation mask. See details in
        https://solutions.mediapipe.dev/pose#enable_segmentation.
      smooth_segmentation: Whether to filter segmentation across different input
        images to reduce jitter. See details in
        https://solutions.mediapipe.dev/pose#smooth_segmentation.
      min_detection_confidence: Minimum confidence value ([0.0, 1.0]) for person
        detection to be considered successful. See details in
        https://solutions.mediapipe.dev/pose#min_detection_confidence.
      min_tracking_confidence: Minimum confidence value ([0.0, 1.0]) for the
        pose landmarks to be considered tracked successfully. See details in
        https://solutions.mediapipe.dev/pose#min_tracking_confidence.
    )rg   smooth_landmarksenable_segmentationsmooth_segmentationuse_prev_landmarks)z@posedetectioncpu__TensorsToDetectionsCalculator.min_score_threshz]poselandmarkbyroicpu__tensorstoposelandmarksandsegmentation__ThresholdingCalculator.threshold)pose_landmarkspose_world_landmarkssegmentation_mask)binary_graph_pathside_inputscalculator_paramsoutputsN)rh   super__init___BINARYPB_FILE_PATH)	selfstatic_image_moderg   rl   rm   rn   min_detection_confidencemin_tracking_confidence	__class__s	           rd   rx   zPose.__init__r   s`    > &&67	G- 0 0 J9J5J#6#=,=(=&7"7
 )'	
 P!  Qrc   imagereturnc                    t         |   d|i      }|j                  r,|j                  j                  D ]  }|j	                  d        |j
                  r,|j
                  j                  D ]  }|j	                  d        |S )a  Processes an RGB image and returns the pose landmarks on the most prominent person detected.

    Args:
      image: An RGB image represented as a numpy ndarray.

    Raises:
      RuntimeError: If the underlying graph throws any error.
      ValueError: If the input image is not three channel RGB.

    Returns:
      A NamedTuple with fields describing the landmarks on the most prominate
      person detected:
        1) "pose_landmarks" field that contains the pose landmarks.
        2) "pose_world_landmarks" field that contains the pose landmarks in
        real-world 3D coordinates that are in meters with the origin at the
        center between hips.
        3) "segmentation_mask" field that contains the segmentation mask if
           "enable_segmentation" is set to true.
    r   )
input_datapresence)rw   processrp   landmark
ClearFieldrq   )rz   r   resultsr   r~   s       rd   r   zPose.process   s    * go'5)9o:G,,55 ((J'(##22;; ((J'(Nrc   )Fr   TFT      ?r   )
r=   r>   r?   r@   rx   npndarrayr   r   __classcell__)r~   s   @rd   rj   rj   h   sB     "' ! $#(#'(+'*0Qd2:: *  rc   rj   )+r@   enumtypingr   numpyr   mediapipe.calculators.corer   r   r   mediapipe.calculators.imager   mediapipe.calculators.tensorr   r	   r
   r   r   r   mediapipe.calculators.tfliter   mediapipe.calculators.utilr   r   r   r   r   r   r   r   mediapipe.framework.toolr   mediapipe.python.solution_baser   mediapipe.python.solutionsr   +mediapipe.python.solutions.pose_connectionsr   IntEnumr   ry   rh   rj   rb   rc   rd   <module>r      s       
 K : B B G A Q M L O C I I I ; I I B J 9 7 5 H"4<< "J S FX< Xrc   