restore coordinates to version before border added

This commit is contained in:
Sefik Ilkin Serengil 2024-06-02 21:06:46 +01:00
parent dcd15cfe81
commit dcd1e80cc0

View File

@ -99,13 +99,15 @@ def detect_faces(
# If faces are close to the upper boundary, alignment move them outside # If faces are close to the upper boundary, alignment move them outside
# Add a black border around an image to avoid this. # Add a black border around an image to avoid this.
height_border = int(0.5 * height)
width_border = int(0.5 * width)
if align is True: if align is True:
img = cv2.copyMakeBorder( img = cv2.copyMakeBorder(
img, img,
int(0.5 * height), height_border,
int(0.5 * height), height_border,
int(0.5 * width), width_border,
int(0.5 * width), width_border,
cv2.BORDER_CONSTANT, cv2.BORDER_CONSTANT,
value=[0, 0, 0], # Color of the border (black) value=[0, 0, 0], # Color of the border (black)
) )
@ -150,6 +152,13 @@ def detect_faces(
int(rotated_y1) : int(rotated_y2), int(rotated_x1) : int(rotated_x2) int(rotated_y1) : int(rotated_y2), int(rotated_x1) : int(rotated_x2)
] ]
# restore x, y, le and re before border added
x = x - width_border
y = y - height_border
# w and h will not change
left_eye = (left_eye[0] - width_border, left_eye[1] - height_border)
right_eye = (right_eye[0] - width_border, right_eye[1] - height_border)
result = DetectedFace( result = DetectedFace(
img=detected_face, img=detected_face,
facial_area=FacialAreaRegion( facial_area=FacialAreaRegion(