popped face recog load_image_fil into a try block as it clearly has/can fail

This commit is contained in:
2024-06-29 13:54:22 +10:00
parent 974d96d6eb
commit 06ceefda97

View File

@@ -5,6 +5,7 @@ import io
import base64
import subprocess
from PIL import Image, ImageOps
import numpy as np
class PA:
def __repr__(self):
@@ -167,10 +168,12 @@ def GenThumb(fname,auto_rotate):
# generate Face data (and location) - wrapper func of face_recognition library
# used to store refimg data into the DB
def GenFace(fname, model):
img = face_recognition.load_image_file(fname)
location = face_recognition.face_locations(img, model=model)
encodings = face_recognition.face_encodings(img, known_face_locations=location)
if len(encodings) and len(location):
return encodings[0].tobytes(), location[0]
else:
return None, None
try:
img = face_recognition.load_image_file(fname)
location = face_recognition.face_locations(img, model=model)
encodings = face_recognition.face_encodings(img, known_face_locations=location)
if len(encodings) and len(location):
return encodings[0].tobytes(), location[0]
except Exception as e:
print( f"GenFace failed: {e}" )
return None, None