Open TanishqRajawat12 opened 3 years ago
The problem is the way the file handling works is it loads the image, it find the faces in it, and then gets the distance. However if there are no faces in the image, it cannot reference the first face. You can fix it by adding an if statement that only gets the distance if there is a face in the image, so it would look something like
if len(face_recognition.face_encodings(face_recognition.load_image_file(myFile)) > 0: print(face_recognition.face_distance(knownPeople, face_recognition.face_encodings(face_recognition.load_image_file(myFile))))
Description
i was trying this code by sentdex in my compiler but i was getting a error, sentdex in his code have assigned [0] in this line encoding = face_recognition.face_encodings(image)[0] while my system is giving error like 'list index out of range' when i copied code from sentdex. but when i tried to remove [0] and made the line like encoding = face_recognition.face_encodings(image) i now am getting another errors what should i do
What I Did
import face_recognition import os import cv2
KNOWN_FACES_DIR = "C:/Users/Admin/Desktop/KnownFaces" TOLERANCE = 0.5 FRAME_THICKNESS = 3 FONT_THICKNESS = 2 MODEL = "cnn" video = cv2.VideoCapture(0) print('Loading known faces...') known_faces = [] known_names = [] for name in os.listdir(KNOWN_FACES_DIR): for filename in os.listdir(f'{KNOWN_FACES_DIR}/{name}'): image = face_recognition.load_image_file(f'{KNOWN_FACES_DIR}/{name}/{filename}') encoding = face_recognition.face_encodings(image)[0] known_faces.append(encoding) known_names.append(name)
print('Processing unknown faces...') while True: