Add catch for no image
This commit is contained in:
parent
2a668b32c5
commit
538f59af6d
1 changed files with 9 additions and 6 deletions
|
@ -79,7 +79,7 @@ class image_classifier:
|
|||
with os.scandir(self.faces_directory) as faces_items:
|
||||
for entry in faces_items:
|
||||
if not entry.name.startswith('.') and entry.is_file():
|
||||
self._log.debug(f"Detecting people in known faces '{entry.name}'...")
|
||||
self._log.debug(f"Detecting known person in file '{entry.name}'...")
|
||||
person = dict()
|
||||
person['filename'] = face_recognition.load_image_file(self.faces_directory + os.sep + entry.name)
|
||||
person['name'] = os.path.splitext(self.faces_directory + os.sep + entry.name)[0]
|
||||
|
@ -89,12 +89,15 @@ class image_classifier:
|
|||
|
||||
def find_faces(self, file):
|
||||
''' Find faces in an image/video file '''
|
||||
image = face_recognition.load_image_file(file)
|
||||
encodings = face_recognition.face_encodings(image)
|
||||
names = list()
|
||||
for known_person in self.known_people:
|
||||
if known_person['encoding'] in encodings:
|
||||
names.append(known_person['name'])
|
||||
try:
|
||||
image = face_recognition.load_image_file(file)
|
||||
encodings = face_recognition.face_encodings(image)
|
||||
for known_person in self.known_people:
|
||||
if known_person['encoding'] in encodings:
|
||||
names.append(known_person['name'])
|
||||
except PIL.UnidentifiedImageError as error:
|
||||
self._log.debug(f"File '{file}' don't seem to be an image.")
|
||||
return names
|
||||
|
||||
def _init_log(self):
|
||||
|
|
Loading…
Reference in a new issue