CoolFace
Apppublic

san021/phi_ratio

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
face_detector.cpython-311.pyc36 linesDownload Raw Back to __pycache__
1�

2���h�3���ddlZddlZddlZddlZej�ej�e��ddd��Z	Gd�de4��ZGd�de5��Zej
��Z	eje	��ZnC#e$r;Zed	e	����ed6��ede����e��YdZ[ndZ[wwxYwd�ZdS)
�Nz..�modelsz%shape_predictor_68_face_landmarks.datc��eZdZdZdS)�NoFaceFoundErrorz>Custom exception raised when no face is detected in the image.N��__name__�7__module__�__qualname__�__doc__���!D:\phi_ratio\src\face_detector.pyrrs������H�H��Drrc��eZdZdZdS)�MultipleFacesFoundErrorz9Custom exception raised when multiple faces are detected.Nrrrr
rrs������C�C��DrrzError loading model from zVPlease make sure you have downloaded the file and placed it in the 'models' directory.zError details: c���tj|tj��}t|d��}t	|��dkrtd���t	|��dkrt
d���t||d��}tj	dd���}tdd��D]9}|�|��j|�|��j
f||<�:|S)	a�8    Detects faces in an image and returns the 68 facial landmarks9    for the first face found.10 11    Args:12        image (numpy.ndarray): The input image (loaded via OpenCV).13 14    Returns:15        numpy.ndarray: A 68x2 NumPy array where each row is an (x, y)16                       coordinate of a facial landmark.17 18    Raises:19        NoFaceFoundError: If no faces are detected in the image.20        MultipleFacesFoundError: If more than one face is detected.21    �rz+No face was detected in the provided image.zDMultiple faces were detected. Please provide an image with one face.)�D��int)�dtyper)�cv2�cvtColor�COLOR_BGR2GRAY�detector�lenrr�	predictor�np�zeros�range�part�x�y)�image�gray�rects�shape�coords�is      r
�
get_landmarksr(!s���"�<��s�1�2�2�D�
�T�1���E��5�z�z�Q����L�M�M�M�22�5�z�z�A�~�~�&�&l�m�m�m�
�d�E�!�H�%�%�E��X�g�U�
+�
+�
+�F�
�1�b�\�\�7�7���Z�Z��]�]�_�e�j�j��m�m�o�6��q�	�	��Mr)r�dlib�numpyr�os�path�join�dirname�__file__�23MODEL_PATH�	Exceptionrr�get_frontal_face_detectorr�shape_predictorr�RuntimeError�e�print�exitr(rrr
�<module>r8se��24�25�26�27���������	�	�	�	�28�W�\�\�"�'�/�/�(�3�3�T�8�El�
m�
m�29�	�	�	�	�	�y�	�	�	�	�	�	�	�	�i�	�	�	�*�4�)�+�+���$��$�Z�0�0�I�I������	�E�302�j�312�322�3�3�3�	�E�33b�c�c�c�	�E�34�A�35�36� � � ��D�F�F�F�F�F�F�F�F�����	����+�+�+�+�+s�2B�C�1B>�>C