I want to create an attendance system which first get the images of the people and when the person comes in front of the camera, it should store the attendance of the person with the date and time of the attendance. The code I am using for the image based Attendance System with face recognition is:
import os
import csv
import numpy as np
import face_recognition
from datetime import datetime
import cv2
video_capture = cv2.VideoCapture(0)
# Loading the data images and encodings
andrea_Bocelli_img = face_recognition.load_image_file("Data/Andrea_Bocelli/Andrea_Bocelli_0001.jpg")
andrea_Bocelli_encoding = face_recognition.face_encodings(andrea_Bocelli_img)[0]
Annette_Bening_img = face_recognition.load_image_file("Data/Annette_Bening/Annette_Bening_0001.jpg")
Annette_Bening_encoding = face_recognition.face_encodings(Annette_Bening_img)[0]
Arnold_Schwarzenegger_img = face_recognition.load_image_file("Data/Arnold_Schwarzenegger/Arnold_Schwarzenegger_0013.jpg")
Arnold_Schwarzenegger_encoding = face_recognition.face_encodings(Arnold_Schwarzenegger_img)[0]
Assad_Ahmadi_img = face_recognition.load_image_file("Data/Assad_Ahmadi/Assad_Ahmadi_0001.jpg")
Assad_Ahmadi_encoding = face_recognition.face_encodings(Assad_Ahmadi_img)[0]
BJ_Habibie_img = face_recognition.load_image_file("Data/BJ_Habibie/BJ_Habibie_0001.jpg")
BJ_Habibie_encoding = face_recognition.face_encodings(BJ_Habibie_img)[0]
Brad_Miller_img = face_recognition.load_image_file("Data/Brad_Miller/Brad_Miller_0001.jpg")
Brad_Miller_encoding = face_recognition.face_encodings(Brad_Miller_img)[0]
Charles_Lebois_img = face_recognition.load_image_file("Data/Charles_Lebois/Charles_Lebois_0001.jpg")
Charles_Lebois_encoding = face_recognition.face_encodings(Charles_Lebois_img)[0]
Chris_Rock_img = face_recognition.load_image_file("Data/Chris_Rock/Chris_Rock_0001.jpg")
Chris_Rock_encoding = face_recognition.face_encodings(Chris_Rock_img)[0]
known_face_encodings = [
andrea_Bocelli_encoding,
Annette_Bening_encoding,
Arnold_Schwarzenegger_encoding,
Assad_Ahmadi_encoding,
BJ_Habibie_encoding,
Brad_Miller_encoding,
Charles_Lebois_encoding,
Chris_Rock_encoding
]
known_face_names = [
"Andrea Bocelli",
"Annette Bening",
"Arnold Schwarzenegger",
"Assad Ahmadi",
"BJ Habibie",
"Brad Miller",
"Charles Lebois",
"Chris Rock"
]
students = known_face_names.copy()
face_locations = []
face_encodings = []
face_names = []
s = True
now = datetime.now()
current_date = now.strftime("%Y-%m-%d")
f = open(current_date+'.csv', 'w+', newline='')
lnwriter = csv.writer(f)
while True:
_, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
if s:
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = ''
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
students.remove(name)
print(students)
current_time = now.strftime("%H-%M-%S")
lnwriter.writerow([name, current_time])
cv2.imshow("Attendance System", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
f.close()
this error is occurring again and again, I have tried multiple things to resolve the error but the issue isn't solved. Can someone please?
The error message which occurred while running the code is:
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\Office\Attendance System\Attendance System.py", line 76, in <module>
face_encodings = face_recognition.face_encodings([rgb_small_frame], face_locations)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\face_recognition\api.py", line 213, in face_encodings
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\face_recognition\api.py", line 165, in _raw_face_landmarks
return [pose_predictor(face_image, face_location) for face_location in face_locations]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\face_recognition\api.py", line 165, in <listcomp>
return [pose_predictor(face_image, face_location) for face_location in face_locations]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __call__(): incompatible function arguments. The following argument types are supported:
1. (self: _dlib_pybind11.shape_predictor, image: numpy.ndarray, box: _dlib_pybind11.rectangle) -> _dlib_pybind11.full_object_detection
Invoked with: <_dlib_pybind11.shape_predictor object at 0x000001DA869EC870>, [array([[[156, 160, 154],
[150, 153, 153],
[146, 152, 154],
...,
[144, 144, 128],
[146, 140, 118],
[144, 138, 117]],
[[150, 162, 157],
[154, 163, 156],
[150, 157, 151],
...,
[147, 139, 127],
[144, 138, 126],
[148, 140, 128]],
[[144, 153, 155],
[144, 154, 153],
[147, 157, 155],
...,
[147, 140, 129],
[145, 138, 127],
[146, 139, 129]],
...,
[[131, 123, 161],
[145, 134, 174],
[170, 160, 185],
...,
[ 30, 30, 29],
[ 30, 29, 29],
[ 40, 35, 35]],
[[125, 122, 155],
[166, 148, 180],
[175, 156, 185],
...,
[ 24, 22, 25],
[ 24, 19, 25],
[ 39, 30, 29]],
[[136, 127, 160],
[170, 152, 175],
[148, 121, 156],
...,
[ 11, 19, 10],
[ 14, 15, 14],
[ 32, 25, 22]]], dtype=uint8)], rectangle(55,41,98,84)
Process finished with exit code 1