Ë
    #ž%hÇ(  ã                   ó  — d dl Zd dlZd dlZd dlmZ 	 d dlZde_
         ej                  «       Z ej                  «       Z ej                  e«      Z ej"                  «       Z ej                  e«      Z ej(                  «       Z ej,                  e«      Z ej0                  «       Z ej4                  e«      Zd„ Zd„ Zd„ Zd	„ Zdd
„Z dd„Z!dd„Z"dd„Z#dd„Z$dd„Z%dd„Z&dd„Z'dd„Z(y# e$ r  ed«        ed«        e	«        Y Œów xY w)é    N)Ú	ImageFilez\Please install `face_recognition_models` with this command before using `face_recognition`:
zCpip install git+https://github.com/ageitgey/face_recognition_modelsTc                 ó~   — | j                  «       | j                  «       | j                  «       | j                  «       fS )zÜ
    Convert a dlib 'rect' object to a plain tuple in (top, right, bottom, left) order

    :param rect: a dlib 'rect' object
    :return: a plain tuple representation of the rect in (top, right, bottom, left) order
    )ÚtopÚrightÚbottomÚleft)Úrects    úR/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/face_recognition/api.pyÚ_rect_to_cssr       s+   € ð �8‰8‹:�t—z‘z“| T§[¡[£]°D·I±I³KÐ?Ð?ó    c                 óJ   — t        j                  | d   | d   | d   | d   «      S )zÔ
    Convert a tuple in (top, right, bottom, left) order to a dlib `rect` object

    :param css:  plain tuple representation of the rect in (top, right, bottom, left) order
    :return: a dlib `rect` object
    é   r   é   é   )ÚdlibÚ	rectangle)Úcsss    r
   Ú_css_to_rectr   *   s)   € ô �>‰>˜#˜a™& # a¡&¨#¨a©&°#°a±&Ó9Ð9r   c                 ó‚   — t        | d   d«      t        | d   |d   «      t        | d   |d   «      t        | d   d«      fS )aX  
    Make sure a tuple in (top, right, bottom, left) order is within the bounds of the image.

    :param css:  plain tuple representation of the rect in (top, right, bottom, left) order
    :param image_shape: numpy shape of the image array
    :return: a trimmed plain tuple representation of the rect in (top, right, bottom, left) order
    r   r   r   r   )ÚmaxÚmin)r   Úimage_shapes     r
   Ú_trim_css_to_boundsr   4   sL   € ô ˆs�1‰v�q‹>œ3˜s 1™v {°1¡~Ó6¼¸CÀ¹FÀKÐPQÁNÓ8SÔUXÐY\Ð]^ÑY_ÐabÓUcÐcÐcr   c                 ó�   — t        | «      dk(  rt        j                  d«      S t        j                  j	                  | |z
  d¬«      S )a”  
    Given a list of face encodings, compare them to a known face encoding and get a euclidean distance
    for each comparison face. The distance tells you how similar the faces are.

    :param faces: List of face encodings to compare
    :param face_to_compare: A face encoding to compare against
    :return: A numpy ndarray with the distance for each face in the same order as the 'faces' array
    r   r   )Úaxis)ÚlenÚnpÚemptyÚlinalgÚnorm)Úface_encodingsÚface_to_compares     r
   Úface_distancer#   ?   s;   € ô ˆ>Ó˜aÒÜ�x‰x˜‹}Ðä�9‰9�>‰>˜.¨?Ñ:Àˆ>ÓCÐCr   c                 ó�   — t         j                  j                  | «      }|r|j                  |«      }t	        j
                  |«      S )a#  
    Loads an image file (.jpg, .png, etc) into a numpy array

    :param file: image file name or file object to load
    :param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
    :return: image contents as numpy array
    )ÚPILÚImageÚopenÚconvertr   Úarray)ÚfileÚmodeÚims      r
   Úload_image_filer-   N   s5   € ô 
�‰�‰˜Ó	€BÙØ�Z‰Z˜ÓˆÜ�8‰8�B‹<Ðr   c                 ó<   — |dk(  rt        | |«      S t        | |«      S )a  
    Returns an array of bounding boxes of human faces in a image

    :param img: An image (as a numpy array)
    :param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
    :param model: Which face detection model to use. "hog" is less accurate but faster on CPUs. "cnn" is a more accurate
                  deep-learning model which is GPU/CUDA accelerated (if available). The default is "hog".
    :return: A list of dlib 'rect' objects of found face locations
    Úcnn)Úcnn_face_detectorÚface_detector)ÚimgÚnumber_of_times_to_upsampleÚmodels      r
   Ú_raw_face_locationsr5   \   s'   € ð �‚~Ü  Ð&AÓBÐBä˜SÐ"=Ó>Ð>r   c                 ó  — |dk(  rBt        | |d«      D �cg c]+  }t        t        |j                  «      | j                  «      ‘Œ- c}S t        | ||«      D �cg c]!  }t        t        |«      | j                  «      ‘Œ# c}S c c}w c c}w )a7  
    Returns an array of bounding boxes of human faces in a image

    :param img: An image (as a numpy array)
    :param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
    :param model: Which face detection model to use. "hog" is less accurate but faster on CPUs. "cnn" is a more accurate
                  deep-learning model which is GPU/CUDA accelerated (if available). The default is "hog".
    :return: A list of tuples of found face locations in css (top, right, bottom, left) order
    r/   )r5   r   r   r	   Úshape)r2   r3   r4   Úfaces       r
   Úface_locationsr9   l   s¡   € ð �‚~ÜTgÐhkð  nIð  KPó  UQö  RÈDÔ#¤L°·±Ó$;¸S¿Y¹YÕGò  Rð  	RäObÐcfð  iDð  FKó  PLö  MÀtÔ#¤L°Ó$6¸¿	¹	ÕBò  Mð  	Mùò Rùò Ms   •0B Á&Bc                 ó   — t        | ||¬«      S )aa  
    Returns an 2d array of dlib rects of human faces in a image using the cnn face detector

    :param img: A list of images (each as a numpy array)
    :param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
    :return: A list of dlib 'rect' objects of found face locations
    )Ú
batch_size)r0   )Úimagesr3   r;   s      r
   Ú_raw_face_locations_batchedr=   |   s   € ô ˜VÐ%@ÈZÔXÐXr   c                 óR   ‡ — ˆ fd„}t        ‰ ||«      }t        t        ||«      «      S )a‡  
    Returns an 2d array of bounding boxes of human faces in a image using the cnn face detector
    If you are using a GPU, this can give you much faster results since the GPU
    can process batches of images at once. If you aren't using a GPU, you don't need this function.

    :param images: A list of images (each as a numpy array)
    :param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
    :param batch_size: How many images to include in each GPU processing batch.
    :return: A list of tuples of found face locations in css (top, right, bottom, left) order
    c                 ó‚   •— | D �cg c].  }t        t        |j                  «      ‰d   j                  «      ‘Œ0 c}S c c}w )Nr   )r   r   r	   r7   )Ú
detectionsr8   r<   s     €r
   Úconvert_cnn_detections_to_cssz;batch_face_locations.<locals>.convert_cnn_detections_to_css’   s1   ø€ ØZdÖeÐRVÔ#¤L°·±Ó$;¸VÀA¹Y¿_¹_ÕMÒeÐeùÒes   †3<)r=   ÚlistÚmap)r<   r3   r;   rA   Úraw_detections_batcheds   `    r
   Úbatch_face_locationsrE   ‡   s0   ø€ ôfô 9¸ÐA\Ð^hÓiÐä”Ð1Ð3IÓJÓKÐKr   c                 ó²   — |€t        | «      }n|D �cg c]  }t        |«      ‘Œ }}t        }|dk(  rt        }|D �cg c]  } || |«      ‘Œ c}S c c}w c c}w )NÚsmall)r5   r   Úpose_predictor_68_pointÚpose_predictor_5_point)Ú
face_imager9   r4   Úface_locationÚpose_predictors        r
   Ú_raw_face_landmarksrM   š   s`   € ØÐÜ,¨ZÓ8‰àKYÖZ¸-œ, }Õ5ÐZˆÐZä,€Nà�ÒÜ/ˆàKYÖZ¸-‰N˜: }Õ5ÒZÐZùò [ùò [s
   “A¼Ac                 ó6  — t        | ||«      }|D ��cg c]6  }|j                  «       D �cg c]  }|j                  |j                  f‘Œ c}‘Œ8 }}}|dk(  r‚|D �cg c]v  }|dd |dd |dd |dd |dd |dd |dd	 |d	d
 |d   gz   |d   gz   |d   gz   |d   gz   |d   gz   |dd |d	   gz   |d   gz   |d   gz   |d   gz   |d   gz   |d   gz   dœ	‘Œx c}S |dk(  r|D �cg c]  }|d   g|dd |dd dœ‘Œ c}S t	        d«      ‚c c}w c c}}w c c}w c c}w )aª  
    Given an image, returns a dict of face feature locations (eyes, nose, etc) for each face in the image

    :param face_image: image to search
    :param face_locations: Optionally provide a list of face locations to check.
    :param model: Optional - which model to use. "large" (default) or "small" which only returns 5 points but is faster.
    :return: A list of dicts of face feature locations (eyes, nose, etc)
    Úlarger   é   é   é   é   é$   é*   é0   é7   é@   é?   é>   é=   é<   é6   éC   éB   éA   )	ÚchinÚleft_eyebrowÚright_eyebrowÚnose_bridgeÚnose_tipÚleft_eyeÚ	right_eyeÚtop_lipÚ
bottom_liprG   é   r   )re   rf   rg   zFInvalid landmarks model type. Supported models are ['small', 'large'].)rM   ÚpartsÚxÚyÚ
ValueError)rJ   r9   r4   Ú	landmarksÚlandmarkÚpÚlandmarks_as_tuplesÚpointss           r
   Úface_landmarksrt   ¨   sÀ  € ô $ J°ÀÓF€IØR[×\Àh°·±Ó0@ÖA¨1˜QŸS™S !§#¡#šJÔAÐ\ÐÑ\ð �Òð ,ö
-ð ð ˜1˜R�LØ" 2 b˜MØ# B r˜]Ø! " R˜=Ø˜r "˜Ø˜r "˜Ø  2˜Ø˜b �}¨¨r©
 |Ñ3°v¸b±z°lÑBÀfÈRÁjÀ\ÑQÐU[Ð\^ÑU_ÐT`Ñ`ÐdjÐkmÑdnÐcoÑoØ   B˜-¨6°"©:¨,Ñ6¸&À¹*¸ÑEÈÐPRÉÈÑTÐX^Ð_aÑXbÐWcÑcÐgmÐnpÑgqÐfrÑrÐv|Ð}ñ  wAð  vBñ  Bó

ò 
-ð 
	-ð 
�'Ò	ð
 ,ö	-ð ð   ™˜Ø˜q ˜Ø  !˜ó
ò -ð 	-ô ÐaÓbÐbùò- BùÓ\ùò
-ùò-s#   “DªDÁ	DÁA;DÃ!DÄDc           
      ó–   — t        | ||«      }|D �cg c],  }t        j                  t        j	                  | ||«      «      ‘Œ. c}S c c}w )aj  
    Given an image, return the 128-dimension face encoding for each face in the image.

    :param face_image: The image that contains one or more faces
    :param known_face_locations: Optional - the bounding boxes of each face if you already know them.
    :param num_jitters: How many times to re-sample the face when calculating encoding. Higher is more accurate, but slower (i.e. 100 is 100x slower)
    :param model: Optional - which model to use. "large" (default) or "small" which only returns 5 points but is faster.
    :return: A list of 128-dimensional face encodings (one for each face in the image)
    )rM   r   r)   Úface_encoderÚcompute_face_descriptor)rJ   Úknown_face_locationsÚnum_jittersr4   Úraw_landmarksÚraw_landmark_sets         r
   r!   r!   Ë   sR   € ô (¨
Ð4HÈ%ÓP€Mð Lö  MÐjzŒB�H‰H”\×9Ñ9¸*ÐFVÐXcÓdÕeò  Mð  Mùò  Ms   ’1Ac                 ó2   — t        t        | |«      |k  «      S )aé  
    Compare a list of face encodings against a candidate encoding to see if they match.

    :param known_face_encodings: A list of known face encodings
    :param face_encoding_to_check: A single face encoding to compare against the list
    :param tolerance: How much distance between faces to consider it a match. Lower is more strict. 0.6 is typical best performance.
    :return: A list of True/False values indicating which known_face_encodings match the face encoding to check
    )rB   r#   )Úknown_face_encodingsÚface_encoding_to_checkÚ	tolerances      r
   Úcompare_facesr€   Ù   s   € ô ”Ð2Ð4JÓKÈyÑXÓYÐYr   )ÚRGB)r   Úhog)r   é€   )NrO   )Nr   rG   )g333333ã?))Ú	PIL.Imager%   r   Únumpyr   r   Úface_recognition_modelsÚ	ExceptionÚprintÚquitÚLOAD_TRUNCATED_IMAGESÚget_frontal_face_detectorr1   Úpose_predictor_model_locationÚpredictor_68_point_modelÚshape_predictorrH   Ú(pose_predictor_five_point_model_locationÚpredictor_5_point_modelrI   Ú cnn_face_detector_model_locationÚcnn_face_detection_modelÚcnn_face_detection_model_v1r0   Úface_recognition_model_locationÚface_recognition_modelÚface_recognition_model_v1rv   r   r   r   r#   r-   r5   r9   r=   rE   rM   rt   r!   r€   © r   r
   ú<module>r˜      sA  ðó Û Û Ý ðÛ"ð #'€	Ô à.�×.Ñ.Ó0€àPÐ2×PÑPÓRÐ Ø.˜$×.Ñ.Ð/GÓHÐ àZÐ1×ZÑZÓ\Ð Ø-˜×-Ñ-Ð.EÓFÐ àSÐ2×SÑSÓUÐ Ø4�D×4Ñ4Ð5MÓNÐ àPÐ0×PÑPÓRÐ Ø-ˆt×-Ñ-Ð.DÓE€ò@ò:òdòDóó?ó Mó YóLó&[ó cóFMô	Zøð_ ò Ù	Ð
iÔjÙ	Ð
OÔPÙ†Fðús   ”C- Ã-DÄD