
    >|h                         d dl mZmZmZmZ d dlZd dlZd dlm	Z	m
Z
mZ d dlmZ 	 	 	 	 	 	 ddeeej                  f   dededed	ed
ededeeeef      fdZy)    )AnyDictListUnionN)modeling	detectionpreprocessing)FacialRecognitionimg_path
model_nameenforce_detectiondetector_backendalignexpand_percentagenormalizationreturnc           	      D   g }t        j                  |      }|j                  }	|dk7  r%t        j                  | |	d   |	d   f|d|||      }
nt        j                  |       \  }}t        |j                        dk(  r|d   }t        |j                        dk(  rt        j                  ||	      }t        j                  |d      }|j                         dkD  r?|j                  t        j                        d	z  j                  t        j                        }|dd|j                  d   |j                  d
   dddg}
|
D ][  }|d   }|d   }|d   }t        j                   ||      }|j#                  |      }i }||d<   ||d<   ||d<   |j%                  |       ] |S )a	  
    Represent facial images as multi-dimensional vector embeddings.

    Args:
        img_path (str or np.ndarray): The exact path to the image, a numpy array in BGR format,
            or a base64 encoded image. If the source image contains multiple faces, the result will
            include information for each detected face.

        model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512,
            OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet

        enforce_detection (boolean): If no face is detected in an image, raise an exception.
            Default is True. Set to False to avoid the exception for low-resolution images.

        detector_backend (string): face detector backend. Options: 'opencv', 'retinaface',
            'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8'.

        align (boolean): Perform alignment based on the eye positions.

        expand_percentage (int): expand detected facial area with a percentage (default is 0).

        normalization (string): Normalize the input image before feeding it to the model.
            Default is base. Options: base, raw, Facenet, Facenet2018, VGGFace, VGGFace2, ArcFace

    Returns:
        results (List[Dict[str, Any]]): A list of dictionaries, each containing the
            following fields:

        - embedding (List[float]): Multidimensional vector representing facial features.
            The number of dimensions varies based on the reference model
            (e.g., FaceNet returns 128 dimensions, VGG-Face returns 4096 dimensions).
        - facial_area (dict): Detected facial area by face detection in dictionary format.
            Contains 'x' and 'y' as the left-corner point, and 'w' and 'h'
            as the width and height. If `detector_backend` is set to 'skip', it represents
            the full image area and is nonsensical.
        - face_confidence (float): Confidence score of face detection. If `detector_backend` is set
            to 'skip', the confidence will be 0 and is nonsensical.
    skip   r   F)r   target_sizer   	grayscaler   r   r         )axisg     o@   )xywh)facefacial_area
confidencer    r!   r"   )imgr   	embeddingface_confidence)r   build_modelinput_shaper   extract_facesr	   
load_imagelenshapecv2resizenpexpand_dimsmaxastypefloat32normalize_inputfind_embeddingsappend)r   r   r   r   r   r   r   	resp_objsmodelr   img_objsr#   _img_objregionr"   r$   resp_objs                     ^/var/www/html/test/engine/venv/lib/python3.12/site-packages/deepface/modules/representation.py	representr>      s   ^ I'33J?E ##K6!**$QQ8-//
 ))(3Qsyy>Qa&Csyy>Q**S+.C..1-Cwwy1}zz"**-5==bjjI
 %&QSYYq\		RSU
  #fo'\*
++=Q))#.	 )"(&0"#"#     )zVGG-FaceTopencvTr   base)typingr   r   r   r   numpyr.   r,   deepface.modulesr   r   r	   !deepface.models.FacialRecognitionr
   strndarrayboolintr>    r?   r=   <module>rK      s    ) )  
 @ ? ?
 !"$fCO$ff f 	f
 f f f 
$sCx.fr?   