ValueError: operands could not be broadcast together with shapes (2,1,128) (413,369,3)
See original GitHub issue- face_recognition version:1.2.3
- Python version: 3.5.4
- Operating System: Windows 10 (x64)
Description
Hi everyone. I am building a facial recognition software that is supposed to identify faces with openCV, take the identified faces, save them as a .jpg file and use that said file for comparison, however there seemed to be some complication when I use the face_recognition.compare_faces function.
What I Did
` def getMatches(self): matches = [] encodings = [] name = “” faceNames = [ “Jass”,“Neo” ] faceToCheck = fr.load_image_file(“facelock.jpg”) faceEncoding = fr.face_encodings(faceToCheck)[0]
face2 = fr.load_image_file("Neo.jpg")
encodings.append(fr.face_encodings(face2)[0])
matches = fr.compare_faces(encodings, faceEncoding)
name = "UNKNOWN"
if True in matches:
ind = matches.index(True)
name = faceNames[ind]
print("The name is:" +str(name))
` I am getting this: Traceback (most recent call last): File “C:\Users\Janda\Desktop\MUKA FINAL\MukaMain.py”, line 201, in getFace self.getMatches() File “C:\Users\Janda\Desktop\MUKA FINAL\MukaMain.py”, line 219, in getMatches matches = fr.compare_faces(encodings, faceEncoding) File “C:\Users\Janda\AppData\Local\Programs\Python\Python35-32\lib\site-packages\face_recognition-1.2.3-py3.5.egg\face_recognition\api.py”, line 222, in compare_faces return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance) File “C:\Users\Janda\AppData\Local\Programs\Python\Python35-32\lib\site-packages\face_recognition-1.2.3-py3.5.egg\face_recognition\api.py”, line 72, in face_distance return np.linalg.norm(face_encodings - face_to_compare, axis=1)
ValueError: operands could not be broadcast together with shapes (1,128) (103,103,3)
Here are the images:
Facelock
Neo
Thank you for your help 😃
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
The issue is when we encode images with improper light on your face, the method face_encoding returns an empty list and when you compare this with that new image’s encoding this error occurs… this might even occur in the reverse case.
@NeoDaenium @ageitgey I am getting this error , tried to resolve by looking some solution mentioned on web but could’nt make it work :
The problem lies over here, encoding = face_recognition.face_encodings(image) known_faces.append(encoding)
Instead of appending encoded list into another list, directly pass the encoding to face_recognition.compare_faces()
known_encoding = face_recognition.face_encodings(image) results = face_recognition.compare_faces(known_encoding, face_encoding, TOLERANCE)
I get what you are trying to achieve with this code, for a rectangle border to be shown on the image:
cv2.rectangle(image, top_left, bottom_right, color, cv2.BORDER_WRAP)