Open shubhamtechgeek opened 3 years ago
* face_recognition version: * Python version: * Operating System:
Description
I am trying to do basic face recognition I keep on getting an error ValueError: operands could not be broadcast together with shapes (1,0) (128,) IMPORTANT: If your issue is related to a specific picture, include it so others can reproduce the issue.
What I Did
import numpy as np import face_recognition as fr import cv2
video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
test_image = fr.load_image_file("test.jpg") test_face_encoding = fr.face_encodings(test_image) if(len(test_face_encoding) > 0): test_face_encoding = test_face_encodings[0] known_face_encodings = [test_face_encoding] known_face_names = ["Shubham"]
while True: ret, frame = video_capture.read()
rgb_frame = frame[:, :, ::-1] face_locations = fr.face_locations(rgb_frame) face_encodings = fr.face_encodings(rgb_frame, face_locations) for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings): matches = fr.compare_faces(known_face_encodings, face_encoding) name = "Unknown" face_distances = fr.face_distance(known_face_encoding, face_encoding) best_match_index = np.argmin(face_distances) if matches[best_match_index]: name = known_face_names[best_match_index] cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) cv2.rectangle(frame, (left, bottom -35), (right, bottom), (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1) cv2.imshow('Webcam_facerecognition', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break
video_capture.release() cv2.destroyAllWindows()
output: Traceback (most recent call last): File "c:\Users\shubh\facerecognition\face_recognition_webcam.py", line 24, in matches = fr.compare_faces(known_face_encodings, face_encoding) File "C:\Users\shubh\facerecognition\venv\lib\site-packages\face_recognition\api.py", line 226, in compare_faces return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance) File "C:\Users\shubh\facerecognition\venv\lib\site-packages\face_recognition\api.py", line 75, in face_distance return np.linalg.norm(face_encodings - face_to_compare, axis=1) ValueError: operands could not be broadcast together with shapes (1,0) (128,)
i have the same issue, how did you solve it
* face_recognition version: * Python version: * Operating System:
Description
I am trying to do basic face recognition I keep on getting an error ValueError: operands could not be broadcast together with shapes (1,0) (128,) IMPORTANT: If your issue is related to a specific picture, include it so others can reproduce the issue.
What I Did
import numpy as np import face_recognition as fr import cv2 video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW) test_image = fr.load_image_file("test.jpg") test_face_encoding = fr.face_encodings(test_image) if(len(test_face_encoding) > 0): test_face_encoding = test_face_encodings[0] known_face_encodings = [test_face_encoding] known_face_names = ["Shubham"] while True: ret, frame = video_capture.read()
rgb_frame = frame[:, :, ::-1] face_locations = fr.face_locations(rgb_frame) face_encodings = fr.face_encodings(rgb_frame, face_locations) for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings): matches = fr.compare_faces(known_face_encodings, face_encoding) name = "Unknown" face_distances = fr.face_distance(known_face_encoding, face_encoding) best_match_index = np.argmin(face_distances) if matches[best_match_index]: name = known_face_names[best_match_index] cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) cv2.rectangle(frame, (left, bottom -35), (right, bottom), (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1) cv2.imshow('Webcam_facerecognition', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break
video_capture.release() cv2.destroyAllWindows() output: Traceback (most recent call last): File "c:\Users\shubh\facerecognition\face_recognition_webcam.py", line 24, in matches = fr.compare_faces(known_face_encodings, face_encoding) File "C:\Users\shubh\facerecognition\venv\lib\site-packages\face_recognition\api.py", line 226, in compare_faces return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance) File "C:\Users\shubh\facerecognition\venv\lib\site-packages\face_recognition\api.py", line 75, in face_distance return np.linalg.norm(face_encodings - face_to_compare, axis=1) ValueError: operands could not be broadcast together with shapes (1,0) (128,)
i have the same issue, how did you solve it
No I was not able to solve it :(
Description
I am trying to do basic face recognition I keep on getting an error ValueError: operands could not be broadcast together with shapes (1,0) (128,) IMPORTANT: If your issue is related to a specific picture, include it so others can reproduce the issue.
What I Did
import numpy as np import face_recognition as fr import cv2
video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
test_image = fr.load_image_file("test.jpg") test_face_encoding = fr.face_encodings(test_image) if(len(test_face_encoding) > 0): test_face_encoding = test_face_encodings[0] known_face_encodings = [test_face_encoding] known_face_names = ["Shubham"]
while True: ret, frame = video_capture.read()
video_capture.release() cv2.destroyAllWindows()
output: Traceback (most recent call last): File "c:\Users\shubh\facerecognition\face_recognition_webcam.py", line 24, in
matches = fr.compare_faces(known_face_encodings, face_encoding)
File "C:\Users\shubh\facerecognition\venv\lib\site-packages\face_recognition\api.py", line 226, in compare_faces
return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance)
File "C:\Users\shubh\facerecognition\venv\lib\site-packages\face_recognition\api.py", line 75, in face_distance
return np.linalg.norm(face_encodings - face_to_compare, axis=1)
ValueError: operands could not be broadcast together with shapes (1,0) (128,)