Vikas01 commited on
Commit
22e0d2f
1 Parent(s): 1db456f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py CHANGED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import face_recognition
2
+ import cv2
3
+ import numpy as np
4
+ import csv
5
+ from datetime import datetime
6
+
7
+ video_capture=cv2.VideoCapture(0)
8
+
9
+ sir_image=face_recognition.load_image_file("photos/sir.jpeg")
10
+ sir_encoding=face_recognition.face_encodings(sir_image)[0]
11
+
12
+ vikas_image=face_recognition.load_image_file("photos/vikas.jpg")
13
+ vikas_encoding=face_recognition.face_encodings(vikas_image)[0]
14
+
15
+ known_face_encoding=[sir_encoding,vikas_encoding]
16
+
17
+ known_faces_names=["Sarwan Sir","Vikas"]
18
+
19
+ students=known_faces_names.copy()
20
+
21
+ face_locations=[]
22
+ face_encodings=[]
23
+ face_names=[]
24
+ s=True
25
+
26
+
27
+
28
+ now=datetime.now()
29
+ current_date=now.strftime("%Y-%m-%d")
30
+
31
+
32
+ f=open(current_date+'.csv','w+',newline='')
33
+ lnwriter=csv.writer(f)
34
+
35
+ while True:
36
+ _,frame=video_capture.read()
37
+ small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
38
+ rgb_small_frame=small_frame[:,:,::-1]
39
+ if s:
40
+ face_locations=face_recognition.face_locations(rgb_small_frame)
41
+ face_encodings = face_recognition.face_encodings(small_frame, face_locations)
42
+ face_names=[]
43
+ for face_encoding in face_encodings:
44
+ matches=face_recognition.compare_faces(known_face_encoding,face_encoding)
45
+ name=""
46
+ face_distance=face_recognition.face_distance(known_face_encoding,face_encoding)
47
+ best_match_index=np.argmin(face_distance)
48
+ if matches[best_match_index]:
49
+ name=known_faces_names[best_match_index]
50
+
51
+ face_names.append(name)
52
+ if name in known_faces_names:
53
+ if name in students:
54
+ students.remove(name)
55
+ print(students)
56
+ current_time=now.strftime("%H-%M-%S")
57
+ lnwriter.writerow([name,current_time,"Present"])
58
+ cv2.imshow("attendence system",frame)
59
+ if cv2.waitKey(1) & 0xFF==ord('q'):
60
+ break
61
+ video_capture.release()
62
+ cv2.destroyAllWindows()
63
+ f.close()