roop/core/config.py
chris 841b2d06c3 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	core/globals.py
#	core/processor.py
#	run.py
2023-05-31 11:35:39 -04:00

29 lines
663 B
Python

import insightface
import core.globals
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
def get_face(img_data):
face = get_face_analyser().get(img_data)
try:
return sorted(face, key=lambda x: x.bbox[0])[0]
except IndexError:
return None
def get_all_faces(img_data):
analysed = face_analyser.get(img_data)
try:
return analysed
except IndexError:
return None