mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 03:55:21 +00:00
retinaface's nose and mouth field are returned in extract faces
This commit is contained in:
parent
6d1d6d32b3
commit
6b115ebac2
@ -45,6 +45,7 @@ class FacialAreaRegion:
|
|||||||
confidence (float, optional): Confidence score associated with the face detection.
|
confidence (float, optional): Confidence score associated with the face detection.
|
||||||
Default is None.
|
Default is None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
x: int
|
x: int
|
||||||
y: int
|
y: int
|
||||||
w: int
|
w: int
|
||||||
@ -52,6 +53,9 @@ class FacialAreaRegion:
|
|||||||
left_eye: Optional[Tuple[int, int]] = None
|
left_eye: Optional[Tuple[int, int]] = None
|
||||||
right_eye: Optional[Tuple[int, int]] = None
|
right_eye: Optional[Tuple[int, int]] = None
|
||||||
confidence: Optional[float] = None
|
confidence: Optional[float] = None
|
||||||
|
nose: Optional[Tuple[int, int]] = None
|
||||||
|
mouth_right: Optional[Tuple[int, int]] = None
|
||||||
|
mouth_left: Optional[Tuple[int, int]] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -63,7 +67,8 @@ class DetectedFace:
|
|||||||
img (np.ndarray): detected face image as numpy array
|
img (np.ndarray): detected face image as numpy array
|
||||||
facial_area (FacialAreaRegion): detected face's metadata (e.g. bounding box)
|
facial_area (FacialAreaRegion): detected face's metadata (e.g. bounding box)
|
||||||
confidence (float): confidence score for face detection
|
confidence (float): confidence score for face detection
|
||||||
"""
|
"""
|
||||||
|
|
||||||
img: np.ndarray
|
img: np.ndarray
|
||||||
facial_area: FacialAreaRegion
|
facial_area: FacialAreaRegion
|
||||||
confidence: float
|
confidence: float
|
||||||
|
@ -42,10 +42,16 @@ class RetinaFaceClient(Detector):
|
|||||||
# retinaface sets left and right eyes with respect to the person
|
# retinaface sets left and right eyes with respect to the person
|
||||||
left_eye = identity["landmarks"]["left_eye"]
|
left_eye = identity["landmarks"]["left_eye"]
|
||||||
right_eye = identity["landmarks"]["right_eye"]
|
right_eye = identity["landmarks"]["right_eye"]
|
||||||
|
nose = identity["landmarks"]["nose"]
|
||||||
|
mouth_right = identity["landmarks"]["mouth_right"]
|
||||||
|
mouth_left = identity["landmarks"]["mouth_left"]
|
||||||
|
|
||||||
# eyes are list of float, need to cast them tuple of int
|
# eyes are list of float, need to cast them tuple of int
|
||||||
left_eye = tuple(int(i) for i in left_eye)
|
left_eye = tuple(int(i) for i in left_eye)
|
||||||
right_eye = tuple(int(i) for i in right_eye)
|
right_eye = tuple(int(i) for i in right_eye)
|
||||||
|
nose = tuple(int(i) for i in nose)
|
||||||
|
mouth_right = tuple(int(i) for i in mouth_right)
|
||||||
|
mouth_left = tuple(int(i) for i in mouth_left)
|
||||||
|
|
||||||
confidence = identity["score"]
|
confidence = identity["score"]
|
||||||
|
|
||||||
@ -57,6 +63,9 @@ class RetinaFaceClient(Detector):
|
|||||||
left_eye=left_eye,
|
left_eye=left_eye,
|
||||||
right_eye=right_eye,
|
right_eye=right_eye,
|
||||||
confidence=confidence,
|
confidence=confidence,
|
||||||
|
nose=nose,
|
||||||
|
mouth_left=mouth_left,
|
||||||
|
mouth_right=mouth_right,
|
||||||
)
|
)
|
||||||
|
|
||||||
resp.append(facial_area)
|
resp.append(facial_area)
|
||||||
|
@ -148,16 +148,26 @@ def extract_faces(
|
|||||||
w = min(width - x - 1, int(current_region.w))
|
w = min(width - x - 1, int(current_region.w))
|
||||||
h = min(height - y - 1, int(current_region.h))
|
h = min(height - y - 1, int(current_region.h))
|
||||||
|
|
||||||
|
facial_area = {
|
||||||
|
"x": x,
|
||||||
|
"y": y,
|
||||||
|
"w": w,
|
||||||
|
"h": h,
|
||||||
|
"left_eye": current_region.left_eye,
|
||||||
|
"right_eye": current_region.right_eye,
|
||||||
|
}
|
||||||
|
|
||||||
|
# optional nose, mouth_left and mouth_right fields are coming just for retinaface
|
||||||
|
if current_region.nose:
|
||||||
|
facial_area["nose"] = current_region.nose
|
||||||
|
if current_region.mouth_left:
|
||||||
|
facial_area["mouth_left"] = current_region.mouth_left
|
||||||
|
if current_region.mouth_right:
|
||||||
|
facial_area["mouth_right"] = current_region.mouth_right
|
||||||
|
|
||||||
resp_obj = {
|
resp_obj = {
|
||||||
"face": current_img,
|
"face": current_img,
|
||||||
"facial_area": {
|
"facial_area": facial_area,
|
||||||
"x": x,
|
|
||||||
"y": y,
|
|
||||||
"w": w,
|
|
||||||
"h": h,
|
|
||||||
"left_eye": current_region.left_eye,
|
|
||||||
"right_eye": current_region.right_eye,
|
|
||||||
},
|
|
||||||
"confidence": round(float(current_region.confidence or 0), 2),
|
"confidence": round(float(current_region.confidence or 0), 2),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +282,9 @@ def expand_and_align_face(
|
|||||||
left_eye = facial_area.left_eye
|
left_eye = facial_area.left_eye
|
||||||
right_eye = facial_area.right_eye
|
right_eye = facial_area.right_eye
|
||||||
confidence = facial_area.confidence
|
confidence = facial_area.confidence
|
||||||
|
nose = facial_area.nose
|
||||||
|
mouth_left = facial_area.mouth_left
|
||||||
|
mouth_right = facial_area.mouth_right
|
||||||
|
|
||||||
if expand_percentage > 0:
|
if expand_percentage > 0:
|
||||||
# Expand the facial region height and width by the provided percentage
|
# Expand the facial region height and width by the provided percentage
|
||||||
@ -305,11 +318,26 @@ def expand_and_align_face(
|
|||||||
left_eye = (left_eye[0] - width_border, left_eye[1] - height_border)
|
left_eye = (left_eye[0] - width_border, left_eye[1] - height_border)
|
||||||
if right_eye is not None:
|
if right_eye is not None:
|
||||||
right_eye = (right_eye[0] - width_border, right_eye[1] - height_border)
|
right_eye = (right_eye[0] - width_border, right_eye[1] - height_border)
|
||||||
|
if nose is not None:
|
||||||
|
nose = (nose[0] - width_border, nose[1] - height_border)
|
||||||
|
if mouth_left is not None:
|
||||||
|
mouth_left = (mouth_left[0] - width_border, mouth_left[1] - height_border)
|
||||||
|
if mouth_right is not None:
|
||||||
|
mouth_right = (mouth_right[0] - width_border, mouth_right[1] - height_border)
|
||||||
|
|
||||||
return DetectedFace(
|
return DetectedFace(
|
||||||
img=detected_face,
|
img=detected_face,
|
||||||
facial_area=FacialAreaRegion(
|
facial_area=FacialAreaRegion(
|
||||||
x=x, y=y, h=h, w=w, confidence=confidence, left_eye=left_eye, right_eye=right_eye
|
x=x,
|
||||||
|
y=y,
|
||||||
|
h=h,
|
||||||
|
w=w,
|
||||||
|
confidence=confidence,
|
||||||
|
left_eye=left_eye,
|
||||||
|
right_eye=right_eye,
|
||||||
|
nose=nose,
|
||||||
|
mouth_left=mouth_left,
|
||||||
|
mouth_right=mouth_right,
|
||||||
),
|
),
|
||||||
confidence=confidence,
|
confidence=confidence,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user