Description
I am facing the issue in my face recognition attendance system project it show the error continously after installing many times:
Please install face_recognition_models
with this command before using face_recognition
:
pip install git+https://github.com/ageitgey/face_recognition_models
This is my code:
import face_recognition
import cv2
import numpy as np
import csv
from datetime import datetime
video_capture=cv2.VideoCapture(0)
#Load Known faces
ujjwal_image=face_recognition.load_image_file("faces/ujjwal.jpg")
ujjwal_encoding=face_recognition.face_encodings(ujjwal_image)[0]
aditya_image=face_recognition.load_image_file("faces/aditya.jpg")
aditya_encoding=face_recognition.face_encodings(aditya_image)[0]
known_face_encodings=[ujjwal_encoding,aditya_encoding]
known_face_names=["Ujjwal","Aditya"]
#List of expected students
students=known_face_names.copy()
face_locations=[]
face_encodings=[]
now=datetime.now()
current_date=datetime.strftime("%Y-%M-%D")
f=open(f"{current_date}.csv","w+",newline="")
lnwriter=csv.writer(f)
while True: #Infinite while loop
_ frame = video_capture.read()
small_frame= cv2.resize(frame, (0,0), fx=0.25 , fy=0.25)
rgb_small_frame= cv2.cvtColor(small_frame,cv2.COLOR_BGR2RGB)
#Recognize faces
face_locations=face_recognition.face_locations(rgb_small_frame)
face_encodings=face_recognition.face_encodings(rgb_small_frame,face_locations)
for face_encoding in face_encodings:
matches=face_recognition.compare_faces(known_face_encodings)
face_distance=face_recognition.face_distance(known_face_encodings,face_encoding)
best_match_index = np.argmin(face_distance)
if(matches[best_match_index]): # Agr ye true hai
name=known_face_names[best_match_index]
cv2.imshow("Attendance", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
video_capture.release()
cv2.destroyAllWindows()
f.close()