-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentification.py
More file actions
74 lines (62 loc) · 2.44 KB
/
identification.py
File metadata and controls
74 lines (62 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import face_recognition
import cv2
import numpy as np
import pyttsx3
from datetime import datetime
# insert to csv file
def makeAttendanceEntry(name):
with open('list.csv','r+') as FILE:
allLines = FILE.readlines()
attendanceList = []
for line in allLines:
entry = line.split(',')
attendanceList.append(entry[0])
if name not in attendanceList:
now = datetime.now()
dtString = now.strftime('%d/%b/%Y, %H:%M:%S')
FILE.writelines(f'\n{name},{dtString}')
# For sound
engine = pyttsx3.init()
frame = cv2.imread('',cv2.IMREAD_GRAYSCALE)
faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
etcodetech_image = face_recognition.load_image_file("EtCodeTech.jpg")
etcodetech_face_encoding = face_recognition.face_encodings(etcodetech_image)[0]
known_face_encoding = [
etcodetech_face_encoding,
known_face_names =["Etcodetech"]
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceDetect.detectMultiScale(gray, 1.3,5)
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
encodings = face_recognition.face_encodings(rgb)
names = []
for encoding in encodings:
matches = face_recognition.compare_faces(known_face_encoding,
encoding)
name = "Unknown"
if True in matches:
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
for i in matchedIdxs:
best_match_index = np.argmin(matches)
name = known_face_names[best_match_index]
counts[name] = counts.get(name, 0) + 1
name = max(counts, key=counts.get)
names.append(name)
for ((x, y, w, h), name) in zip(faces, names):
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.putText(frame, name, (x, y), cv2.FONT_HERSHEY_SIMPLEX,
0.75, (0, 255, 0), 2)
if matches [0] == True:
engine.say("Good Morning, please go to your class" )
makeAttendanceEntry(name)
else:
engine.say("Please try again, i don't recognize you")
engine.runAndWait()
cv2.imshow("absent", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()