Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Ai_Attendence_Project in python #554

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/Ai_Attendence_Project.py/Attendence.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ELON MUSK,20:12:05,08/12/2021
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions projects/Ai_Attendence_Project.py/Readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Ai_Attendence_Project
<br>
This Program detects the face of the given members and will record the presence
in attendence.csv file with date and time
#Libraries Used

1. Dlib
2. face-recognition
3. os
4. cv2
5. numpy
6. dateandtime
76 changes: 76 additions & 0 deletions projects/Ai_Attendence_Project.py/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import cv2
import numpy as np
import face_recognition
import os
from datetime import datetime

path = 'Images'
Images = []
PersonName = []
mylist = os.listdir(path)
print(mylist)
# for separating the name from their extensions
for cu_img in mylist:
current_Img = cv2.imread(f'{path}/{cu_img}')
Images.append(current_Img)
PersonName.append(os.path.splitext(cu_img)[0])
print(PersonName)


def encodings(images):
encodelist = []
for img in images:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encode = face_recognition.face_encodings(img)[0]
encodelist.append(encode)
return encodelist


encode_list_Known = encodings(Images)
print("ALL ENCODING FOUND!!!")


def attendance(name):
with open('Attendence.csv', 'r+') as f:
myDataList = f.readlines()
nameList = []
for line in myDataList:
entry = line.split(',')
nameList.append(entry[0])
if name not in nameList:
time_now = datetime.now()
tStr = time_now.strftime('%H:%M:%S')
dStr = time_now.strftime('%d/%m/%Y')
f.writelines(f'\n{name},{tStr},{dStr}')


cap = cv2.VideoCapture(0)

while True:
ret, frame = cap.read()
faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25)
faces = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

faces_currentframe = face_recognition.face_locations(faces)
encode_currentframe = face_recognition.face_encodings(faces, faces_currentframe)

for encodeFace, faceLoc in zip(encode_currentframe, faces_currentframe):
matches = face_recognition.compare_faces(encode_list_Known, encodeFace)
faceDistance = face_recognition.face_distance(encode_list_Known, encodeFace)

matchIndex = np.argmin(faceDistance)

if matches[matchIndex]:
name = PersonName[matchIndex].upper()
y1, x2, y2, x1 = faceLoc
#y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
cv2.rectangle(frame, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
cv2.putText(frame, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
attendance(name)

cv2.imshow("camera", frame)
if cv2.waitKey(10) == 13:
break
cap.release()
cv2.destroyAllWindows()