简体   繁体   中英

face_recognition compare faces function giving odd outputs

I want to compare the face encodings of a list of encodings and a sample image

#init empty dictionary for each folder name
dictionary = {name:[] for name in os.listdir(ROOT)}



#saves encodings in a list to the dictionary with corresponding names
for folder in os.listdir(ROOT):
    for image in os.listdir(os.path.join(ROOT,folder)):
        img = face_recognition.load_image_file(f"{ROOT}/{folder}/{image}")
        dictionary[folder].append(face_recognition.face_encodings(img))

#dict looks something like this: {name:[encoding1,encoding2....]}


#sample image
my_image = face_recognition.load_image_file("vedank.jpg")
face_encodings = face_recognition.face_encodings(my_image,face_recognition.face_locations(my_image))

#taking user input to access dictionary values
user = input("enter your username")

#print results of face comparison
print(face_recognition.compare_faces(np.array(face_encodings[0]),np.array(dictionary[user])))

Here's the output while comparing the encodings of 'my_image' with the encodings of 2 other images:

[array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True]), array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True])]

Why do I get multiple boolean values? When I try to compare two images by manually loading both (instead of going through the whole dictionary process) I get a single boolean value (which is what it should look like).

Edit: I tried playing around with it and it looks like appending the encodings to a list is causing the problem. Any idea on how to fix this?

I want to compare the face encodings of a list of encodings and a sample image

#init empty dictionary for each folder name
dictionary = {name:[] for name in os.listdir(ROOT)}



#saves encodings in a list to the dictionary with corresponding names
for folder in os.listdir(ROOT):
    for image in os.listdir(os.path.join(ROOT,folder)):
        img = face_recognition.load_image_file(f"{ROOT}/{folder}/{image}")
        dictionary[folder].append(face_recognition.face_encodings(img))

#dict looks something like this: {name:[encoding1,encoding2....]}


#sample image
my_image = face_recognition.load_image_file("vedank.jpg")
face_encodings = face_recognition.face_encodings(my_image,face_recognition.face_locations(my_image))

#taking user input to access dictionary values
user = input("enter your username")

#print results of face comparison
print(face_recognition.compare_faces(np.array(face_encodings[0]),np.array(dictionary[user])))

Here's the output while comparing the encodings of 'my_image' with the encodings of 2 other images:

[array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True]), array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True])]

Why do I get multiple boolean values? When I try to compare two images by manually loading both (instead of going through the whole dictionary process) I get a single boolean value (which is what it should look like).

Edit: I tried playing around with it and it looks like appending the encodings to a list is causing the problem. Any idea on how to fix this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM