Ë
    »dæjÙ3  ã                   ó6  — d Z ddlZddlZddlmZmZm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ZdZdZej.                  j0                  Zd	Zd
ZdZdZdZej>                   G d„ d«      «       Z de!de!de"de"dede#e"e"f   f   f
d„Z$ e e¬«       e «       fdejJ                  dejL                  de de fd„Z'd e e¬«       e «       dfdejJ                  de(ejR                     dee(e      deee ee"e f   f      d ee ee#e"e"f   e f   f   d!e*fd"„Z+d#d$d% e «       fdejJ                  d&ejJ                  d'ejJ                  d(e#e!e!f   d)e#e!e!f   d*e!d+e fd,„Z,d-„ Z-d e ed.¬/«       e ed.¬/«      d0d0fde(ejR                     dee(e#e"e"f         de d e d1e"d2e"fd3„Z.y)4z!MediaPipe solution drawing utils.é    N)ÚMappingÚOptionalÚUnion)Ú
detections)Úlandmark)Úface_landmarkerç      à?é   )éà   r   r   ©r   r   r   )r   r   éÿ   )r   é€   r   )r   r   r   c                   óD   — e Zd ZU eZeeeef   ed<   dZeed<   dZ	eed<   y)ÚDrawingSpecÚcoloré   Ú	thicknessÚcircle_radiusN)
Ú__name__Ú
__module__Ú__qualname__ÚWHITE_COLORr   ÚtupleÚintÚ__annotations__r   r   © ó    ún/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/mediapipe/tasks/python/vision/drawing_utils.pyr   r   (   s-   … ð !,€%ˆˆs�C˜ˆ}Ñ	Ó+à€)ˆSÓà€-�Ôr   r   Únormalized_xÚnormalized_yÚimage_widthÚimage_heightÚreturnc                 óà   — dt         dt        fd„} || «      r ||«      syt        t        j                  | |z  «      |dz
  «      }t        t        j                  ||z  «      |dz
  «      }||fS )z4Converts normalized value pair to pixel coordinates.Úvaluer#   c                 óz   — | dkD  xs t        j                  d| «      xr | dk  xs t        j                  d| «      S )Nr   é   )ÚmathÚisclose)r%   s    r   Úis_valid_normalized_valuezC_normalized_to_pixel_coordinates.<locals>.is_valid_normalized_value;   s?   € Ø�A‰IÒ/œŸ™ a¨Ó/ò N°e¸a±iò 7MÜ6:·l±lÀ1ÀeÓ6LðNr   Nr'   )ÚfloatÚboolÚminr(   Úfloor)r   r    r!   r"   r*   Úx_pxÚy_pxs          r   Ú _normalized_to_pixel_coordinatesr1   2   st   € ðN¤uð N´ó Nñ $ LÔ
1Ù
# LÔ
1àÜ	ŒT�Z‰Z˜ {Ñ2Ó3°[À1±_Ó	E€$Ü	ŒT�Z‰Z˜ |Ñ3Ó4°lÀQÑ6FÓ	G€$Ø	ˆtˆÐr   ©r   ÚimageÚ	detectionÚkeypoint_drawing_specÚbbox_drawing_specc                 ó¸  — | j                   d   t        k7  rt        d«      ‚| j                   \  }}}|j                  rj|j                  D ][  }t	        |j
                  |j                  ||«      }t        j                  | ||j                  |j                  |j                  «       Œ] |j                  j                  |j                  j                  f}	|j                  j                  |j                  j                  z   |j                  j                  |j                  j                   z   f}
t        j"                  | |	|
|j                  |j                  «       y)a'  Draws the detction bounding box and keypoints on the image.

  Args:
    image: A three channel BGR image represented as numpy ndarray.
    detection: A detection object with a bounding box.
    keypoint_drawing_spec: A DrawingSpec object that specifies the keypoints'
      drawing settings such as color, line thickness, and circle radius.
    bbox_drawing_spec: A DrawingSpec object that specifies the bounding box's
      drawing settings such as color and line thickness.

  Raises:
    ValueError: If the input image is not three channel BGR.
  r   ú0Input image must contain three channel bgr data.N)ÚshapeÚ_BGR_CHANNELSÚ
ValueErrorÚ	keypointsr1   ÚxÚyÚcv2Úcircler   r   r   Úbounding_boxÚorigin_xÚorigin_yÚwidthÚheightÚ	rectangle)r3   r4   r5   r6   Ú
image_rowsÚ
image_colsÚ_ÚkeypointÚkeypoint_pxÚrect_start_pointÚrect_end_points              r   Údraw_detectionrN   H   s3  € ð& ‡[�[��^”}Ò$Ü
ÐGÓ
HÐHØ#Ÿk™kÑ€*ˆj˜!ð ×ÒØ×'Ñ'ò 
ˆÜ4Ø
�*‰*�h—j‘j *¨jó€kô 
‡j�jØ
Ø
Ø
×
-Ñ
-Ø
×
%Ñ
%Ø
×
)Ñ
)õð	
ð ×Ñ×%Ñ%Ø×Ñ×%Ñ%ðÐð
 ×Ñ×%Ñ%¨	×(>Ñ(>×(DÑ(DÑDØ×Ñ×%Ñ%¨	×(>Ñ(>×(EÑ(EÑEð€.ô ‡-�-�Ð'¨Ø!×'Ñ'Ð):×)DÑ)DõFr   TÚlandmark_listÚconnectionsÚlandmark_drawing_specÚconnection_drawing_specÚis_drawing_landmarksc                 óJ  — |sy| j                   d   t        k7  rt        d«      ‚| j                   \  }}}i }	t        |«      D ]n  \  }
}|j                  �|j                  t
        k  s|j                  �|j                  t        k  rŒEt        |j                  |j                  ||«      }|sŒj||	|
<   Œp |r­t        |«      }|D ]�  }|j                  }|j                  }d|cxk  r|k  rn nd|cxk  r|k  sn t        d|› d|› d�«      ‚||	v sŒM||	v sŒRt        |t        «      r|||f   n|}t!        j"                  | |	|   |	|   |j$                  |j&                  «       ŒŸ |rÀ|r½|	j)                  «       D ]©  \  }
}t        |t        «      r||
   n|}t+        |j,                  dz   t/        |j,                  d	z  «      «      }t!        j0                  | ||t2        |j&                  «       t!        j0                  | ||j,                  |j$                  |j&                  «       Œ« yyy)
a¼  Draws the landmarks and the connections on the image.

  Args:
    image: A three channel BGR image represented as numpy ndarray.
    landmark_list: A list of normalized landmarks to be annotated on the image.
    connections: A list of landmark index tuples that specifies how landmarks to
      be connected in the drawing.
    landmark_drawing_spec: Either a DrawingSpec object or a mapping from hand
      landmarks to the DrawingSpecs that specifies the landmarks' drawing
      settings such as color, line thickness, and circle radius. If this
      argument is explicitly set to None, no landmarks will be drawn.
    connection_drawing_spec: Either a DrawingSpec object or a mapping from hand
      connections to the DrawingSpecs that specifies the connections' drawing
      settings such as color and line thickness. If this argument is explicitly
      set to None, no landmark connections will be drawn.
    is_drawing_landmarks: Whether to draw landmarks. If set false, skip drawing
      landmarks, only contours will be drawed.

  Raises:
    ValueError: If one of the followings:
      a) If the input image is not three channel BGR.
      b) If any connetions contain invalid landmark index.
  Nr   r8   r   úBLandmark index is out of range. Invalid connection from landmark #ú to landmark #ú.r'   g333333ó?)r9   r:   r;   Ú	enumerateÚ
visibilityÚ_VISIBILITY_THRESHOLDÚpresenceÚ_PRESENCE_THRESHOLDr1   r=   r>   ÚlenÚstartÚendÚ
isinstancer   r?   Úliner   r   ÚitemsÚmaxr   r   r@   r   )r3   rO   rP   rQ   rR   rS   rG   rH   rI   Úidx_to_coordinatesÚidxr   Úlandmark_pxÚnum_landmarksÚ
connectionÚ	start_idxÚend_idxÚdrawing_specÚcircle_border_radiuss                      r   Údraw_landmarksrm   z   sQ  € ñF 
Ø
Ø
‡[�[��^”}Ò$Ü
ÐGÓ
HÐHØ#Ÿk™kÑ€*ˆj˜!ØÐÜ  Ó/ò ,�m€cˆ8à×ÑÐ'Ø×ÑÔ"7Ò7à×ÑÐ%Ø×ÑÔ 3Ò3àÜ2°8·:±:¸x¿z¹zØ3=¸zóK€KâØ +Ð˜Òð,ñ Ü˜Ó&€Mà!ò )ˆ
Ø×"Ñ"€iØ—‘€gØ�9Ô,˜}Õ,°°gÔ1MÀÔ1MÜð +Ø+4¨+°^ÀGÀ9ÈAðOó Pð 	Pà	Ð(Ò	(¨WÐ8JÒ-Jô Ð1´7Ô;ð $ Y°Ð$8Ò9à(ð 	ô
 	�‰�Ð*¨9Ñ5Ø# GÑ,¨l×.@Ñ.@Ø×'Ñ'õ	)ð)ñ" Ñ3Ø.×4Ñ4Ó6ò 
=Ñˆˆ[Ü3=Ø
¤ô4*Ð*¨3Ò/Ø/Dð ô ! ×!;Ñ!;¸aÑ!?Ü!$ \×%?Ñ%?À#Ñ%EÓ!FóHÐä	‡j�j�˜Ð%9¼;Ø×'Ñ'ô)ô 
‡j�j�˜ \×%?Ñ%?Ø×#Ñ# \×%;Ñ%;õ=ñ
=ð 4Ðr   )ç      ð?rn   )ç        ro   gš™™™™™¹?ÚrotationÚtranslationÚfocal_lengthÚprincipal_pointÚaxis_lengthÚaxis_drawing_specc                 ó|  — | j                   d   t        k7  rt        d«      ‚| j                   \  }}}	t        j                  g d¢g d¢g d¢g d¢g«      }
t        j
                  |||
j                  z  «      j                  |z   }|d   }|d   }|d	   }|\  }}|\  }}t        j                  | |z  |d
z   z  |z   dd«      }t        j                  | |z  |d
z   z  |z   dd«      }t        j                  d|z   dz  |z  «      }t        j                  d|z
  dz  |z  «      }|d   |d   f}|d   |d   f}|d   |d   f}|d   |d   f}t        j                  | ||t        |j                  «       t        j                  | ||t        |j                  «       t        j                  | ||t        |j                  «       y)aŽ  Draws the 3D axis on the image.

  Args:
    image: A three channel BGR image represented as numpy ndarray.
    rotation: Rotation matrix from object to camera coordinate frame.
    translation: Translation vector from object to camera coordinate frame.
    focal_length: camera focal length along x and y directions.
    principal_point: camera principal point in x and y.
    axis_length: length of the axis in the drawing.
    axis_drawing_spec: A DrawingSpec object that specifies the xyz axis drawing
      settings such as line thickness.

  Raises:
    ValueError: If one of the followings:
      a) If the input image is not three channel BGR.
  r   r8   r   )r'   r   r   )r   r'   r   )r   r   r'   ).r   ).r'   ).r   gñhãˆµøä>g      ð¿rn   r'   r	   r   r
   N)r9   r:   r;   ÚnpÚfloat32ÚmatmulÚTÚclipÚint32r?   ÚarrowedLineÚ	RED_COLORr   ÚGREEN_COLORÚ
BLUE_COLOR)r3   rp   rq   rr   rs   rt   ru   rG   rH   rI   Ú
axis_worldÚaxis_camr=   r>   ÚzÚfxÚfyÚpxÚpyÚx_ndcÚy_ndcÚx_imÚy_imÚoriginÚx_axisÚy_axisÚz_axiss                              r   Ú	draw_axisr�   Ò   s¼  € ð2 ‡[�[��^”}Ò$Ü
ÐGÓ
HÐHØ#Ÿk™kÑ€*ˆj˜!ä�z‰zš9¢i²ºIÐFÓG€*Ü�Y‰Y�x ¨z¯|©|Ñ!;Ó<×>Ñ>ÀÑL€(ØˆvÑ€!ØˆvÑ€!ØˆvÑ€!à�&€"€bØ�&€"€bÜ
�'‰'�2�#˜‘'˜Q ™XÑ&¨Ñ+¨S°"Ó
5€%Ü
�'‰'�2�#˜‘'˜Q ™XÑ&¨Ñ+¨S°"Ó
5€%ä	�‰�1�u‘9 Ñ# jÑ0Ó	1€$Ü	�‰�1�u‘9 Ñ# jÑ0Ó	1€$à�‰G�T˜!‘WÐ€&Ø�‰G�T˜!‘WÐ€&Ø�‰G�T˜!‘WÐ€&Ø�‰G�T˜!‘WÐ€&Ü‡/�/�%˜ ¬Ð4E×4OÑ4OÔPÜ‡/�/�%˜ ¬Ø#×-Ñ-ô/ä‡/�/�%˜ ¬Ø#×-Ñ-õ/r   c                 ó&   — t        d„ | D «       «      S )Nc              3   ó&   K  — | ]	  }|d z  –— Œ y­w)g     ào@Nr   )Ú.0Úvs     r   ú	<genexpr>z#_normalize_color.<locals>.<genexpr>	  s   è ø€ Ò'˜Aˆq�4�xÑ'ùs   ‚)r   r2   s    r   Ú_normalize_colorr–     s   € Ü	Ñ' Ô'Ó	'Ð'r   é   )r   r   é
   Ú	elevationÚazimuthc                 óü  — | syt        j                  d¬«       t        j                  d¬«      }|j                  ||¬«       i }t	        | «      D ]Ô  \  }}	|	j
                  �|	j
                  t        k  s|	j                  �|	j                  t        k  rŒE|j                  |	j                   xs dg|	j                  xs dg|	j                   xs dgt        |j                  ddd…   «      |j                  ¬	«       |	j                   |	j                  |	j                   f||<   ŒÖ |rÀt!        | «      }
|D ]°  }|d   }|d
   }d|cxk  r|
k  rn nd|cxk  r|
k  sn t#        d|› d|› d�«      ‚||v sŒ?||v sŒD||   ||   g}|j%                  |d   d   |d
   d   g|d   d
   |d
   d
   g|d   d   |d
   d   gt        |j                  ddd…   «      |j                  ¬	«       Œ² t        j&                  «        y)aº  Plot the landmarks and the connections in matplotlib 3d.

  Args:
    landmark_list: A list of normalized landmarks to be plotted.
    connections: A list of landmark index tuples that specifies how landmarks to
      be connected.
    landmark_drawing_spec: A DrawingSpec object that specifies the landmarks'
      drawing settings such as color and line thickness.
    connection_drawing_spec: A DrawingSpec object that specifies the
      connections' drawing settings such as color and line thickness.
    elevation: The elevation from which to view the plot.
    azimuth: the azimuth angle to rotate the plot.

  Raises:
    ValueError: If any connection contains an invalid landmark index.
  N)r˜   r˜   )ÚfigsizeÚ3d)Ú
projection)ÚelevÚazimr   éÿÿÿÿ)ÚxsÚysÚzsr   Ú	linewidthr'   rU   rV   rW   r   )ÚpltÚfigureÚaxesÚ	view_initrX   rY   rZ   r[   r\   Ú	scatter3Drƒ   r=   r>   r–   r   r   r]   r;   Úplot3DÚshow)rO   rP   rQ   rR   r™   rš   ÚaxÚplotted_landmarksre   r   rg   rh   ri   rj   Úlandmark_pairs                  r   Úplot_landmarksr°     s>  € ñ8 
Ø
Ü‡*�*�XÕÜ
‡x�x˜4Ô €"Ø‡,�,�I G€,Ô,ØÐÜ  Ó/ò D�m€cˆ8à×ÑÐ'Ø×ÑÔ"7Ò7à×ÑÐ%Ø×ÑÔ 3Ò3àØ‡L�LØ�Z‰ZˆKÒ˜1ÐØ�J‰JŠO˜!ÐØ�Z‰ZˆKÒ˜1ÐÜÐ4×:Ñ:¹4¸R¸4Ñ@ÓAØ'×1Ñ1ð ô ð  (Ÿz™z˜k¨8¯:©:¸¿
¹
°{ÐCÐ�cÒð!Dñ" Ü˜Ó&€Mà!ò 9ˆ
Ø˜Q‘-€iØ˜1‘€gØ�9Ô,˜}Õ,°°gÔ1MÀÔ1MÜð +Ø+4¨+°^ÀGÀ9ÈAðOó Pð 	Pà	Ð'Ò	'¨GÐ7HÒ,Hà˜iÑ(Ð*;¸GÑ*Dð
ˆð 	�	‰	Ø˜aÑ  Ñ# ]°1Ñ%5°aÑ%8Ð9Ø˜aÑ  Ñ# ]°1Ñ%5°aÑ%8Ð9Ø˜aÑ  Ñ# ]°1Ñ%5°aÑ%8Ð9Ü"Ð#:×#@Ñ#@ÁÀ2ÀÑ#FÓGØ-×7Ñ7ð 	õ 	9ð9ô  ‡(�(…*r   )/Ú__doc__Údataclassesr(   Útypingr   r   r   r?   Úmatplotlib.pyplotÚpyplotr¦   Únumpyrw   Ú,mediapipe.tasks.python.components.containersr   Údetections_moduler   Úlandmark_moduleÚmediapipe.tasks.python.visionr   r\   rZ   r:   ÚFaceLandmarksConnectionsÚ
ConnectionÚ_CONNECTIONr   ÚBLACK_COLORr~   r   r€   Ú	dataclassr   r+   r   r   r1   ÚndarrayÚ	DetectionrN   ÚlistÚNormalizedLandmarkr,   rm   r�   r–   r°   r   r   r   ú<module>rÄ      sÆ  ðñ (ã Û ß +Ñ +ã 
Ý Û å XÝ TÝ 9àÐ ØÐ Ø€Ø×6Ñ6×AÑA€à€Ø€Ø€	Ø€Ø€
ð ×Ñ÷ð ó ððØðàðð ðð ð	ð
 ˆ4��s˜C�x‘Ð Ñ!óñ2 *5¸9Ô)EÙ%0£]ñ	/FØ�:‰:ð/Fà ×*Ñ*ð/Fð 'ð/Fð #ó	/Fðj 04ñ 	˜)Ô$ñ 	‹Ø!%ñU=Ø�:‰:ðU=à˜×:Ñ:Ñ;ðU=ð ˜$˜{Ñ+Ñ,ðU=ð $Øˆk˜7 3¨Ð#3Ñ4Ð4Ñ5ñð	U=ð #Ø�W˜U 3¨ 8™_¨kÐ9Ñ:Ð:ñðU=ð óU=ðx )3Ø+5ØÙ%0£]ñ3/Ø�:‰:ð3/à�j‰jð3/ð —‘ð3/ð ˜˜u˜Ñ%ð	3/ð
 ˜5 %˜<Ñ(ð3/ð ð3/ð #ó3/òl(ð 48Ù)4Ø 1ô*ñ ,7Ø Qô,ð ØñFØ˜×:Ñ:Ñ;ðFà˜$˜u S¨# X™Ñ/Ñ0ðFð 'ðFð )ðFð ðFð ôFr   