-
Notifications
You must be signed in to change notification settings - Fork 0
/
attendanceVideo.py
57 lines (46 loc) · 2.06 KB
/
attendanceVideo.py
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
import cv2
import numpy as np
import face_recognition
import os
from Functions import findEncoding, markAttendance
def startVideo(videoPath):
path = 'database'
imageList = []
personName = []
dataList = os.listdir(path)
for data in dataList:
curImage = cv2.imread(f'{path}/{data}')
imageList.append(curImage)
curName = os.path.splitext(data)[0]
personName.append(curName)
print('Starting Encoding of Know Images in Database...')
encodedKnown = findEncoding(imageList, personName)
print('Encoding of Known Images Completed...')
cap = cv2.VideoCapture(videoPath)
while True:
ret, frame = cap.read()
frameS = cv2.resize(frame, (0, 0), None, 0.25, 0.25)
frameS = cv2.cvtColor(frameS, cv2.COLOR_BGR2RGB)
cv2.putText(frame, "Press Esc to Exit", (10, 450), cv2.FONT_HERSHEY_TRIPLEX, 0.6, (255, 255, 255), 2)
curFaceFrame = face_recognition.face_locations(frameS)
curEncoding = face_recognition.face_encodings(frameS, curFaceFrame)
for encoding, faceFrame in zip(curEncoding, curFaceFrame):
result = face_recognition.compare_faces(encodedKnown, encoding)
faceDist = face_recognition.face_distance(encodedKnown, encoding)
Index = np.argmin(faceDist)
y1, x2, y2, x1 = faceFrame
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
if faceDist[Index] < 0.55 and result:
name = personName[Index].upper()
print(name)
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(frame, f'{name}', (x1, y1-5), cv2.FONT_HERSHEY_COMPLEX, 1, (0,255, 0))
markAttendance(name, "AttendanceVideo.csv")
else:
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv2.putText(frame, f'unknown', (x1, y1-5), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255))
cv2.imshow("Webcam", frame)
key = cv2.waitKey(1)
if key == 27:
cv2.destroyWindow("Webcam")
break