0

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?

mp.jpeg
  • 197
  • 2
  • 18
  • What's the output when you execute `print(results[0])`? – Shubham Sharma Mar 28 '20 at 04:57
  • [ True True True True True True True True True True True True True True True True True True True True True True True True ] – mp.jpeg Mar 28 '20 at 05:00
  • @mp.jpeg This stackoverflow answer: https://stackoverflow.com/a/28900165/7548672 I think gives a good explanation to your error and why the suggestion is to use any() or all(). –  Mar 28 '20 at 05:03

0 Answers0