From b97f74e18679fdc2271b3baefa5aca7c7b340d3f Mon Sep 17 00:00:00 2001 From: "Anthr@X" Date: Thu, 13 Jul 2023 22:13:32 +1000 Subject: [PATCH] fix linting and add comments --- deepface/detectors/YunetWrapper.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/deepface/detectors/YunetWrapper.py b/deepface/detectors/YunetWrapper.py index cc15e03..eeaa265 100644 --- a/deepface/detectors/YunetWrapper.py +++ b/deepface/detectors/YunetWrapper.py @@ -13,9 +13,7 @@ def build_model(): print(f"{file_name} will be downloaded...") output = home + f"/.deepface/weights/{file_name}" gdown.download(url, output, quiet=False) - face_detector = cv2.FaceDetectorYN_create( - home + f"/.deepface/weights/{file_name}", "", (0, 0) - ) + face_detector = cv2.FaceDetectorYN_create(home + f"/.deepface/weights/{file_name}", "", (0, 0)) return face_detector @@ -52,10 +50,11 @@ def detect_face(detector, image, align=True, score_threshold=0.9): {x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye, left eye, nose tip, the right corner and left corner of the mouth respectively. """ (x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8])) - if x < 0: - x = 0 - if y < 0: - y = 0 + + # Yunet returns negative coordinates if it thinks part of the detected face is outside the frame. + # We set the coordinate to 0 if they are negative. + x = max(x, 0) + y = max(y, 0) if resized: image = original_image x, y, w, h = int(x / r), int(y / r), int(w / r), int(h / r)