I have a face recognition file that searches a folder for 'Known' faces then searches another folder to try and see those face.
To search through the folder of known faces I have:
my_dir = './img/known/'
encoding_for_file = []
for i in os.listdir(my_dir):
image = my_dir + i
image = face_recognition.load_image_file(image)
image_encoding = face_recognition.face_encodings(image)
encoding_for_file.append(image_encoding[0])
The code then searches a folder for a face and if it finds one, shows the image.
for i in range (1, 8+1):
#Construct the picture name and print it
file_name = f"./img/unknown/{str(i).zfill(5)}.jpg"
print(file_name)
#Load the file
newPic = face_recognition.load_image_file(file_name)
#Search every detected face
for face_encoding in face_recognition.face_encodings(newPic):
results = face_recognition.compare_faces([image_encoding], face_encoding)
#If match, show it
if results[0] == True:
img = Image.open(file_name)
img.show()
However I get a "Truth Value of Array is ambiguous error on the following line:
if results[0] == True:
It suggests using a.any() or a.all() - which I have not used.
Any suggestions?