2023-05-28 17:49:40 +03:00
|
|
|
import insightface
|
2023-05-30 02:03:43 +03:00
|
|
|
import core.globals
|
2023-05-28 17:49:40 +03:00
|
|
|
|
2023-05-30 17:29:51 +03:00
|
|
|
FACE_ANALYSER = None
|
|
|
|
|
|
|
|
|
|
|
|
def get_face_analyser():
|
|
|
|
global FACE_ANALYSER
|
|
|
|
if FACE_ANALYSER is None:
|
|
|
|
FACE_ANALYSER = insightface.app.FaceAnalysis(name='buffalo_l', providers=core.globals.providers)
|
|
|
|
FACE_ANALYSER.prepare(ctx_id=0, det_size=(640, 640))
|
|
|
|
return FACE_ANALYSER
|
2023-05-28 17:49:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
def get_face(img_data):
|
2023-05-30 17:29:51 +03:00
|
|
|
face = get_face_analyser().get(img_data)
|
2023-05-29 15:20:26 +03:00
|
|
|
try:
|
2023-05-30 17:29:51 +03:00
|
|
|
return sorted(face, key=lambda x: x.bbox[0])[0]
|
2023-05-29 15:20:26 +03:00
|
|
|
except IndexError:
|
|
|
|
return None
|