I'm trying to make the code recognize two people but i don't know how to do it so far. Made a directory that caontains the images taken from my webcam. I have another that works fine but it only show my name. this is my code. It keeps showing Unknown.It is going to be for a surveillance system.
import cv2 import face_recognition as fr import numpy as np vide_capture = cv2.VideoCapture(0) user_image = fr.load_image_file('Database/user.jpg') user_face_encoding = fr.face_encodings(user_image)[0] user2_image = fr.load_image_file('Database/user2.jpg') user2_face_encoding = fr.face_encodings(user2_image)[0] known_faces_encodings = [user_face_encoding] known_faces_names = ['Daniel'] known_faces_encodings2 = [user2_face_encoding] known_faces_names2 = ['Elon'] def Video_detect(): while True: ret, frame = vide_capture.read() rgb_frame = frame[:, :, ::-1] face_location = fr.face_locations(rgb_frame) face_encodings = fr.face_encodings(rgb_frame, face_location) for (top, right, bottom, left), face_encoding in zip(face_location, face_encodings): match = fr.compare_faces(known_faces_encodings, face_encoding) name = 'Unknown' match2 = fr.compare_faces(known_faces_encodings2, face_encoding) name2 = 'Unknown' face_distances = fr.face_distance(known_faces_encodings, face_encoding) face_distances2 = fr.face_distance(known_faces_encodings2, face_encoding) best_match_index = np.argmin(face_distances) best_match_index2 = np.argmin(face_distances2) if match[best_match_index] and match2[best_match_index2]: name = known_faces_names[best_match_index] name2 = known_faces_names2[best_match_index2] cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) cv2.rectangle(frame, (left, bottom - 15), (right, bottom), (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(frame, name, (left + 3, bottom - 3), font, 0.5, (255, 255, 255), 1) cv2.putText(frame, name2, (left + 3, bottom - 3), font, 0.5, (255, 255, 255), 1) cv2.imshow('Webcam_face_recognition', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break vide_capture.release(Video_detect()) cv2.destroyAllWindows() https://stackoverflow.com/questions/66468421/face-recognition-2-profiles March 04, 2021 at 12:05PM
没有评论:
发表评论