Open Mutleymuffin opened 5 years ago
Your photo seems to contain (at least) 10 people. When you call this function:
unknown_face = face_recognition.face_encodings(unknown_image)
That doesn't give you one unknown_face. That gives you an array of 10 unknown faces it found in the image.
so instead of doing this:
unknown_face = face_recognition.face_encodings(unknown_image)
result = face_recognition.compare_faces(face_encodings, unknown_face)
You need to do this instead to handle each detected face individually:
# unknown faces is an array with one entry for each detected face
unknown_faces = face_recognition.face_encodings(unknown_image)
for unknown_face in unknown_faces:
result = face_recognition.compare_faces(face_encodings, unknown_face)
# Do whatever you want with the result for each face
Description
I followed your guide on the wiki as to how to save faces to a file, but I have encountered an issue. Whenever I run using an image which contains an unknown face, it returns an error:
ValueError: operands could not be broadcast together with shapes (3,128) (10,128)
I have discovered that this only appears when the image which is being searched contains a face which is unknown to the stored faces in the file. Could you please provide me with a code solution to avoid this error appearing when there is an unknown face present.
Other people who have asked this question have either not received a useful answer or haven't posted how they've fixed it.
What I Did
CODE:
ERROR: