-
Notifications
You must be signed in to change notification settings - Fork 4
/
attendance_window.py
163 lines (139 loc) · 5.7 KB
/
attendance_window.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import cv2
import numpy as np
import os
import time
from PIL import Image
import shutil
import sqlite3
from check_attendance import CheckAttendance
from PyQt4 import QtGui,QtCore
conn=sqlite3.connect('Attendance System.db')
c=conn.cursor()
class AttendanceWindow(QtGui.QMainWindow):
#Attendance Window
def __init__(self):
super(AttendanceWindow, self).__init__()
self.setGeometry(300,50,800,600)
self.setWindowTitle("Attendance")
self.setWindowIcon(QtGui.QIcon('other_images/logo.png'))
#Heading
h=QtGui.QLabel(self)
h.setAlignment(QtCore.Qt.AlignCenter)
h.setGeometry(QtCore.QRect(200,20,400,50))
h.setStyleSheet("QLabel { background-color : blue;color :white ; }")
font=QtGui.QFont("Times",20,QtGui.QFont.Bold)
h.setFont(font)
h.setText("ATTENDANCE")
#Label and Subject code entry
l=QtGui.QLabel(self)
l.setAlignment(QtCore.Qt.AlignCenter)
l.setGeometry(QtCore.QRect(275,140,250,30))
l.setStyleSheet("QLabel { background-color:green;color: white;}")
font=QtGui.QFont("Times",16,QtGui.QFont.Bold)
l.setFont(font)
l.setText("ENTER SUB-CODE")
self.e = QtGui.QLineEdit(self)
self.e.setGeometry(275,175,250,50)
self.e.setAlignment(QtCore.Qt.AlignCenter)
self.e.setFont(QtGui.QFont("Times",18,QtGui.QFont.Bold))
#Recording Button
b1=QtGui.QPushButton(self)
b1.setText("RECORD AND MARK")
b1.setStyleSheet("QPushButton { background-color : gray;color : black ; }")
b1.setFont(font)
b1.setGeometry(250,300,300,50)
b1.clicked.connect(self.record_and_mark)
#Check Attendance button to check specific subject's Attendance
b2=QtGui.QPushButton(self)
b2.setText("CHECK ATTENDANCE")
b2.setStyleSheet("QPushButton { background-color : gray;color : black ; }")
b2.setFont(font)
b2.setGeometry(250,425,300,50)
b2.clicked.connect(self.create_check_attendance)
def create_check_attendance(self):
#To check Validity of Subject Code
sub=["IT301","IT302"] #TO DO - GET THESE FROM TABLE
if self.e.text() in sub:
self._check_attendance = CheckAttendance(self.e.text())
self._check_attendance.show()
def record_and_mark(self):
self.record() #to record the video and save it to folder 'videos'
self.mark()
def record(self):
#to save video with the name self.e.text()
return
def mark(self):
#self.get_snaps() #to get snaps from the recorded video
#self.extract_faces() #to read all faces from the snaps
self.match() #match extracted faces to those in database and update the database
def get_snaps(self):
shutil.rmtree("temp",ignore_errors=True)
os.mkdir("temp")
os.mkdir("temp/presentFaces")
video_name = str(self.e.text())
crop_time = 2
time_gap = 2
#cv2 object created that uses the video capture function to open the video file
cap = cv2.VideoCapture("videos/"+video_name+".mp4")
fps = int(cap.get(cv2.CAP_PROP_FPS))
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
count = fps*(crop_time)
i = 0
cap.set(1,68)
while (cap.isOpened()):
ret , frame = cap.read()
if(count>length):
break
cv2.waitKey(3)
if( (count == (crop_time*fps + i*time_gap*fps)) &(count < length)):
cv2.imwrite('temp/frame'+str(i)+'.jpg',frame)
i = i+1
print('snap taken @', count)
count = count + 1
cap.release()
cv2.destroyAllWindows()
print (i, "snaps taken")
def extract_faces(self):
i=0
face_cascade = cv2.CascadeClassifier("support_files/haarcascade_frontalface_default.xml")
for eachImg in os.listdir("temp"):
print(eachImg, 'read')
img = cv2.imread("temp/" + eachImg, 0)
faces = face_cascade.detectMultiScale(img)
for(x,y,w,h) in faces:
sub_face = img[y:y+h, x:x+w]
face_file_name = "temp/presentFaces/face_" + str(i) + ".jpg"
cv2.imwrite(face_file_name,sub_face)
i=i+1
cv2.waitKey(0)
cv2.destroyAllWindows()
print (i, 'faces read')
def match(self):
subject = str(self.e.text())
# registration picts are in "registration_images/Year2" -> picts are labelled with roll no.
# extracted faces are in "temp/presentFaces"
present = [1, 13, 19, 33, 39, 70] #this list will have the rolls of students that are present.
# getting all the rolls, names of year 2 students from database
xyear = (int(subject[2])+1)//2
query='SELECT * FROM YEAR{};'.format(xyear)
c.execute(query)
rolls = []
names = []
for row in c.fetchall():
rolls.append(row[0])
names.append(row[1])
temp = []
for r in rolls:
if (r in present):
temp.append('P')
else:
temp.append('A')
rolls = list(map(str, rolls))
query='INSERT INTO {} (Date,{}) VALUES (20171018,{});'.format(subject, ','.join(rolls), ','.join(temp))
print (query)
c.execute(query)
if __name__ == '__main__':
app = QtGui.QApplication([])
gui = AttendanceWindow()
gui.show()
app.exec_()