unit test to confirm all faces detected

This commit is contained in:
Sefik Ilkin Serengil 2024-12-24 11:11:50 +00:00
parent d11ca8ff22
commit a8269767f3

View File

@ -119,13 +119,19 @@ def image_to_base64(image_path):
def test_facial_coordinates_are_in_borders():
detectors = ["retinaface", "mtcnn"]
expected_faces = [7, 6]
img_path = "dataset/selfie-many-people.jpg"
img = cv2.imread(img_path)
height, width, _ = img.shape
results = DeepFace.extract_faces(img_path=img_path)
for i, detector_backend in enumerate(detectors):
results = DeepFace.extract_faces(img_path=img_path, detector_backend=detector_backend)
assert len(results) > 0
# this is a hard example, mtcnn can detect 6 and retinaface can detect 7 faces
# be sure all those faces detected. any change in detection module can break this.
assert len(results) == expected_faces[i]
for result in results:
facial_area = result["facial_area"]
@ -140,4 +146,4 @@ def test_facial_coordinates_are_in_borders():
assert x + w < width
assert y + h < height
logger.info("✅ facial area coordinates are all in image borders")
logger.info(f"✅ facial area coordinates are all in image borders for {detector_backend}")