Skip to content

Commit 745b4b8

Browse files
committed
set left and right eye locations with respect to the person instead of observer
1 parent 2b5c139 commit 745b4b8

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

deepface/detectors/Dlib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
8888

8989
shape = self.model["sp"](img, detection)
9090

91-
left_eye = (
91+
right_eye = (
9292
int((shape.part(2).x + shape.part(3).x) // 2),
9393
int((shape.part(2).y + shape.part(3).y) // 2),
9494
)
95-
right_eye = (
95+
left_eye = (
9696
int((shape.part(0).x + shape.part(1).x) // 2),
9797
int((shape.part(0).y + shape.part(1).y) // 2),
9898
)

deepface/detectors/FastMtCnn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
3434
):
3535
for regions, confidence, eyes in zip(*detections):
3636
x, y, w, h = xyxy_to_xywh(regions)
37-
left_eye = eyes[0]
38-
right_eye = eyes[1]
37+
right_eye = eyes[0]
38+
left_eye = eyes[1]
3939

4040
left_eye = tuple(int(i) for i in left_eye)
4141
right_eye = tuple(int(i) for i in right_eye)

deepface/detectors/MediaPipe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
6161
y = int(bounding_box.ymin * img_height)
6262
h = int(bounding_box.height * img_height)
6363

64-
left_eye = (int(landmarks[0].x * img_width), int(landmarks[0].y * img_height))
65-
right_eye = (int(landmarks[1].x * img_width), int(landmarks[1].y * img_height))
64+
right_eye = (int(landmarks[0].x * img_width), int(landmarks[0].y * img_height))
65+
left_eye = (int(landmarks[1].x * img_width), int(landmarks[1].y * img_height))
6666
# nose = (int(landmarks[2].x * img_width), int(landmarks[2].y * img_height))
6767
# mouth = (int(landmarks[3].x * img_width), int(landmarks[3].y * img_height))
6868
# right_ear = (int(landmarks[4].x * img_width), int(landmarks[4].y * img_height))

deepface/detectors/MtCnn.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
3535
for current_detection in detections:
3636
x, y, w, h = current_detection["box"]
3737
confidence = current_detection["confidence"]
38-
left_eye = current_detection["keypoints"]["left_eye"]
39-
right_eye = current_detection["keypoints"]["right_eye"]
38+
# mtcnn detector assigns left eye with respect to the observer
39+
# but we are setting it with respect to the person itself
40+
left_eye = current_detection["keypoints"]["right_eye"]
41+
right_eye = current_detection["keypoints"]["left_eye"]
4042

4143
facial_area = FacialAreaRegion(
4244
x=x,

deepface/detectors/OpenCv.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,18 @@ def find_eyes(self, img: np.ndarray) -> tuple:
112112
eye_2 = eyes[1]
113113

114114
if eye_1[0] < eye_2[0]:
115-
left_eye = eye_1
116-
right_eye = eye_2
117-
else:
118-
left_eye = eye_2
119115
right_eye = eye_1
116+
left_eye = eye_2
117+
else:
118+
right_eye = eye_2
119+
left_eye = eye_1
120120

121121
# -----------------------
122122
# find center of eyes
123-
left_eye = (int(left_eye[0] + (left_eye[2] / 2)), int(left_eye[1] + (left_eye[3] / 2)))
123+
left_eye = (
124+
int(left_eye[0] + (left_eye[2] / 2)),
125+
int(left_eye[1] + (left_eye[3] / 2)),
126+
)
124127
right_eye = (
125128
int(right_eye[0] + (right_eye[2] / 2)),
126129
int(right_eye[1] + (right_eye[3] / 2)),

deepface/detectors/RetinaFace.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
3434
x = detection[0]
3535
w = detection[2] - x
3636

37-
# notice that these must be inverse for retinaface
38-
left_eye = identity["landmarks"]["right_eye"]
39-
right_eye = identity["landmarks"]["left_eye"]
37+
# retinaface sets left and right eyes with respect to the person
38+
left_eye = identity["landmarks"]["left_eye"]
39+
right_eye = identity["landmarks"]["right_eye"]
4040

4141
# eyes are list of float, need to cast them tuple of int
4242
left_eye = tuple(int(i) for i in left_eye)

deepface/detectors/Yolo.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
8181
x, y, w, h = result.boxes.xywh.tolist()[0]
8282
confidence = result.boxes.conf.tolist()[0]
8383

84-
# left_eye_conf = result.keypoints.conf[0][0]
85-
# right_eye_conf = result.keypoints.conf[0][1]
86-
left_eye = result.keypoints.xy[0][0].tolist()
87-
right_eye = result.keypoints.xy[0][1].tolist()
84+
# right_eye_conf = result.keypoints.conf[0][0]
85+
# left_eye_conf = result.keypoints.conf[0][1]
86+
right_eye = result.keypoints.xy[0][0].tolist()
87+
left_eye = result.keypoints.xy[0][1].tolist()
8888

8989
# eyes are list of float, need to cast them tuple of int
9090
left_eye = tuple(int(i) for i in left_eye)

deepface/detectors/YuNet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
9999
{x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye,
100100
left eye, nose tip, the right corner and left corner of the mouth respectively.
101101
"""
102-
(x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8]))
102+
(x, y, w, h, x_le, y_le, x_re, y_re) = list(map(int, face[:8]))
103103

104104
# YuNet returns negative coordinates if it thinks part of the detected face
105105
# is outside the frame.

0 commit comments

Comments
 (0)