-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo.py
46 lines (34 loc) · 1.34 KB
/
video.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
from datetime import datetime
import cv2
from face_prediction import predict_face
from mail import send_email
from repositories.attendance_repository import get_attendance, save_attendance
from repositories.student_repository import get_all_students
def mark_attendance(course_id):
students = get_all_students()
if len(students) == 0:
raise Exception("No Student Found")
video_capture = cv2.VideoCapture(0)
attendance = set()
while True:
_, frame = video_capture.read()
labelled_frame, student = predict_face(frame, students)
if student is not None:
attendance.add(student.id)
cv2.imshow(
"Frame", labelled_frame if labelled_frame is not None else frame
)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
video_capture.release()
cv2.destroyAllWindows()
today = datetime.now().date().isoformat()
marked_attendance = map(
lambda record: record["studentID"], get_attendance(today, course_id))
attendance_to_mark = filter(
lambda record: record not in marked_attendance, attendance)
absent_students = filter(
lambda student: student.id not in attendance_to_mark and student.id not in marked_attendance, students
)
save_attendance(today, course_id, attendance_to_mark)
send_email(absent_students)