
    ihs                     B    d dl mZmZ d dlZd dlmZmZ  G d de      Zy)    )AnyListN)DetectorFacialAreaRegionc                   H    e Zd Zd ZdefdZdej                  dee	   fdZ
y)MediaPipeClientc                 .    | j                         | _        y )N)build_modelmodel)selfs    Z/var/www/html/dev/engine/venv/lib/python3.12/site-packages/deepface/detectors/MediaPipe.py__init__zMediaPipeClient.__init__	   s    %%'
    returnc                     	 ddl }|j                  j                  }|j                  d      }|S # t        $ r}t        d      |d}~ww xY w)z`
        Build a mediapipe face detector model
        Returns:
            model (Any)
        r   NzpMediaPipe is an optional detector, ensure the library is installed.Please install using 'pip install mediapipe' gffffff?)min_detection_confidence)	mediapipeModuleNotFoundErrorImportError	solutionsface_detectionFaceDetection)r   mpemp_face_detectionr   s        r   r
   zMediaPipeClient.build_model   s`    	" LL77*88RU8V # 	@ 	s   0 	A
AA
imgc           
         g }|j                   d   }|j                   d   }| j                  j                  |      }|j                  |S |j                  D ],  }|j                  \  }|j
                  j                  }|j
                  j                  }	t        |j                  |z        }
t        |j                  |z        }t        |j                  |z        }t        |j                  |z        }t        |	d   j                  |z        t        |	d   j                  |z        f}t        |	d   j                  |z        t        |	d   j                  |z        f}t        |
||||||      }|j!                  |       / |S )z
        Detect and align face with mediapipe

        Args:
            img (np.ndarray): pre-loaded image as numpy array

        Returns:
            results (List[FacialAreaRegion]): A list of FacialAreaRegion objects
           r   )xywhleft_eye	right_eye
confidence)shaper   process
detectionsscorelocation_datarelative_bounding_boxrelative_keypointsintxminwidthyminheightr   r    r   append)r   r   resp	img_width
img_heightresultscurrent_detectionr%   bounding_box	landmarksr   r!   r    r"   r#   r$   facial_areas                    r   detect_faceszMediaPipeClient.detect_faces   sr    IIaL	YYq\
**$$S) %K ")!3!3 	%-33MZ,::PPL)77JJIL%%	12AL&&23AL%%
23AL''*45AIaLNNY67Yq\^^j=X9YZHYq\^^i78#ilnnz>Y:Z[I +qAXWaK KK$+	%. r   N)__name__
__module____qualname__r   r   r
   npndarrayr   r   r;    r   r   r   r      s0    (S &-

 -t4D/E -r   r   )	typingr   r   numpyr?   deepface.models.Detectorr   r   r   rA   r   r   <module>rE      s      ?
Dh Dr   