Computer vision based Attendance System.

Computer vision-based Attendance System.

Environment setup/Project Requirements :
  1. Python
  2. OpenCV, Numpy, face_recognition libraries need to be installed.
  3. Jupyter Notebook/Pycharm/ Atom 
Note: You cannot implement this project in Google-Colaboratory or in any python online Interpreter
Workflow:
  1. Importing Data (training images)
  2. Finding the faces and encodings 
  3. Comparing the encodings with the other face encodings
  4. Finding distances of the encodings.
  5. Visualizing the Findings 
  6. Finding the path to images automatically
  7. Looping through images
  8. Finding Encodings of the Face 
  9. Accessing WebCam
  10. Iterating through the faces and encodings
  11. Bounding boxes and visualizing the results 
  12. Attendance in CSV file
Step 1: Importing data. 
Firstly, we need to import the data in order to test the model. Since we have to test the model, whether it's predicting correctly or not, we need to take two inputs test image and the target image.
imgElon = face_recognition.load_image_file('Images/ElonMusk.jpg')
imgTest = face_recognition.load_image_file('Images/billagtes.jpg')
Step 2: Finding faces and encodings of the face. 
We find the recordings of the face in order to classify the faces so, in order to find the encodings of the face, we need to find the face in the image first. After locating the face we need to visualize the location, so we keep a bounding box around it.
faceLoc = face_recognition.face_locations(imgElon)[0]
encodeElon = face_recognition.face_encodings(imgElon)[0]
cv2.rectangle(imgElon, (faceLoc[3], faceLoc[0]), (faceLoc[1], faceLoc[2]), (25500), 2)
Step 3: Comparing the face encodings.
In order to evaluate the model, we need to compare the encodings of the faces and predict whether they were matched or not.
results = face_recognition.compare_faces([encodeElon], encodeTest) 
Step 4: Finding the facial distances.
We give the attendance based on the similarity of the encodings, so in order to find the best match, we need to find the distance between encodings. The closer the distance, the closer the similar the encodings are.
faceDis = face_recognition.face_distance([encodeElon], encodeTest)
Step 5: Visualizing the findings.
We have to see whether it predicted true or false, so we need to visualize the predictions.
cv2.putText(imgTest, f'{results} {round(faceDis[0], 2)}', (5050), 
cv2.FONT_HERSHEY_COMPLEX, 1, (00255), 2)
Step 6: Finding the path for images automatically.
We shouldn't do all this manually, so we have to automate the process using the "os" library/module.
myList = os.listdir(path)
Step 7:Loop through images.
We loop through the images and the names, we divide the images and names into two lists and append them into two empty lists by removing .jpg or .png extensions.
for cl in myList:
    images.append(curImg) 
    classNames.append(os.path.splitext(cl)[0]) 
Step 8:Finding the encodings of Faces.
We have to find the encodings of the images in order to differentiate faces and append the encodings into some empty list.
for img in images:
    encode = face_recognition.face_encodings(img)[0]
    encodeList.append(encode)
Step 9:Accessing webCam
We need to give the live attendance, we need to access the live camera and read the live video/images.
cap = cv2.VideoCapture(0)
while True:
    success, img = cap.read()
Step 10:Iterating through images.
We resize the images to half (or) a quarter of the original size to reduce the time complexity. So we have to reiterate through the entire resized images and find the face location and find the encodings.
for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
    matches = face_recognition.compare_faces(encodeListKnown, encodeFace)
    faceDis = face_recognition.face_distance(encodeListKnown, encodeFace) 
Step 11:Bounding boxes and visualizing the results.
So, in order to see the results predicted by the model, we need to visualize the results by resizing the images into their original size.
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
cv2.rectangle(img, (x1, y1), (x2, y2), (02550), 2)
cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255255255), 2)
Step 12:Attendence in CSV file.
Since we have to mark attendance we create a CSV file with Name and Time. We have to use the "file handling" method in python to read the file and loop through names and we print time along with that. 
for line in myDataList:
    entry = line.split(','# we split line based on comma
    nameList.append(entry[0])
if name not in nameList: # if there is no name we will just write the time.
    now = datetime.now()
    dtString = now.strftime('%H:%M:%S')
    f.writelines(f'\n{name},{dtString}')

Note: You can access the complete code in my GitHub.
Note: Thanks for each and every opensource contributor(StackOverflow, Github, Answersmind) and Adam Geitgey

Expected viva:

1)What is the use of the project?
A) Nowadays, the attendance system was wasting most of the class time during the class, and in virtual classes, like Zoom, we cannot take manual attendance so in order to overcome those issues we developed a new attendance system.

2)What is the difference between your project and other existing projects?
A) usually, many of attendance systems based on facial recognition uses large databases of images, In our project we no need to use such large databases instead we use just one image for each person.

3) Tell the drawbacks of this project?
A)As we know there can be proxies because aa the system gives attendance even for your photograph. we have to manage that by installing it in a perfect place in the class.

4)What if the camera sees multiple images at a time?
A) Good Question, To overcome the issue of double attendance we are finding the location of the faces and sending it to find the encodings.

5) What if it marks attendance while leaving the class?
A)Actually, for that we need to install two cameras per classroom at defined places so that we can also measure the duration of the class, probably this may work fine.

6)Can this compete with the biometric attendance system?
A)I'm not pretty sure, but I think the biometric system is costly compared to the camera. Well, anyway we need to install at least one camera for a class in that case, we no need to afford a new biometric system. Biometric systems cannot be used in zoom sessions right!, we can use this system there.

7)Through which algorithm you classified the faces?
A)Internally we have used an SVM classifier.

made with 💓by Sai Dheeraj


Comments

Popular posts from this blog

Object Detection Using OpenCV and Transfer Learning.

Path Detection based on Bird Eye view with OpenCV module

Traffic signs recognition with convolutional Neural networks