get max_faces number faces from largest

This commit is contained in:
Sefik Ilkin Serengil 2024-07-17 17:23:23 +01:00
parent c66804717c
commit 010bb2b1f0

View File

@ -97,7 +97,17 @@ def represent(
]
# ---------------------------------
for idx, img_obj in enumerate(img_objs):
if max_faces is not None and max_faces < len(img_objs):
# sort as largest facial areas come first
img_objs = sorted(
img_objs,
key=lambda img_obj: img_obj["facial_area"]["w"] * img_obj["facial_area"]["h"],
reverse=True,
)
# discard rest of the items
img_objs = img_objs[0:max_faces]
for img_obj in img_objs:
if anti_spoofing is True and img_obj.get("is_real", True) is False:
raise ValueError("Spoof detected in the given image.")
img = img_obj["face"]
@ -128,7 +138,4 @@ def represent(
}
)
if max_faces is not None and max_faces > 0 and max_faces > idx + 1:
break
return resp_objs