issue 100 - if detected face has 0 in some dimension

This commit is contained in:
Şefik Serangil 2020-09-27 09:11:05 +03:00
parent f04cfbf689
commit e6da083983

View File

@ -450,13 +450,20 @@ def preprocess_face(img, target_size=(224, 224), grayscale = False, enforce_dete
#img might be path, base64 or numpy array. Convert it to numpy whatever it is.
img = load_image(img)
base_img = img.copy()
img = detect_face(img = img, detector_backend = detector_backend, grayscale = grayscale, enforce_detection = enforce_detection)
#--------------------------
#we will align base image instead of detected face not have black pixels
img = detect_face(img = img, detector_backend = detector_backend, grayscale = grayscale, enforce_detection = enforce_detection)
if img.shape[0] > 0 and img.shape[1] > 0:
img = align_face(img = img, detector_backend = detector_backend)
else:
if enforce_detection == True:
raise ValueError("Detected face shape is ", img.shape,". Consider to set enforce_detection argument to False.")
else: #restore base image
img = base_img.copy()
#--------------------------