Skip to content

Commit 5518a5d

Browse files
authored
Merge pull request #1191 from serengil/feat-task-1604-detect-after-align-bug
Feat task 1604 detect after align bug
2 parents 5bb411f + f6a226e commit 5518a5d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

deepface/detectors/CenterFace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ def detect_faces(self, img: np.ndarray) -> List["FacialAreaRegion"]:
8282
# mouth_left = (int(landmark[8]), int(landmark [9]))
8383

8484
facial_area = FacialAreaRegion(
85-
x=x,
86-
y=y,
87-
w=w,
88-
h=h,
85+
x=int(x),
86+
y=int(y),
87+
w=int(w),
88+
h=int(h),
8989
left_eye=left_eye,
9090
right_eye=right_eye,
9191
confidence=min(max(0, float(confidence)), 1.0),

deepface/detectors/DetectorWrapper.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,30 @@ def rotate_facial_area(
175175
# Angle in radians
176176
angle = angle * np.pi / 180
177177

178+
height, weight = size
179+
178180
# Translate the facial area to the center of the image
179-
x = (facial_area[0] + facial_area[2]) / 2 - size[1] / 2
180-
y = (facial_area[1] + facial_area[3]) / 2 - size[0] / 2
181+
x = (facial_area[0] + facial_area[2]) / 2 - weight / 2
182+
y = (facial_area[1] + facial_area[3]) / 2 - height / 2
181183

182184
# Rotate the facial area
183185
x_new = x * np.cos(angle) + y * direction * np.sin(angle)
184186
y_new = -x * direction * np.sin(angle) + y * np.cos(angle)
185187

186188
# Translate the facial area back to the original position
187-
x_new = x_new + size[1] / 2
188-
y_new = y_new + size[0] / 2
189+
x_new = x_new + weight / 2
190+
y_new = y_new + height / 2
189191

190-
# Calculate the new facial area
192+
# Calculate projected coordinates after alignment
191193
x1 = x_new - (facial_area[2] - facial_area[0]) / 2
192194
y1 = y_new - (facial_area[3] - facial_area[1]) / 2
193195
x2 = x_new + (facial_area[2] - facial_area[0]) / 2
194196
y2 = y_new + (facial_area[3] - facial_area[1]) / 2
195197

196-
return (int(x1), int(y1), int(x2), int(y2))
198+
# validate projected coordinates are in image's boundaries
199+
x1 = max(int(x1), 0)
200+
y1 = max(int(y1), 0)
201+
x2 = min(int(x2), weight)
202+
y2 = min(int(y2), height)
203+
204+
return (x1, y1, x2, y2)

0 commit comments

Comments
 (0)