Vikas01 commited on
Commit
17aa4ec
1 Parent(s): a104a54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -47
app.py CHANGED
@@ -4,70 +4,74 @@ 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
  ############################
36
  import io
37
  import streamlit as st
38
- bytes_data=None
39
 
40
- img_file_buffer=st.camera_input("Take a picture")
41
  if img_file_buffer is not None:
42
-
43
  while True:
44
- _,frame=video_capture.read()
45
- small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
46
- rgb_small_frame=small_frame[:,:,::-1]
47
- if s:
48
- face_locations=face_recognition.face_locations(rgb_small_frame)
49
- face_encodings = face_recognition.face_encodings(small_frame, face_locations)
50
- face_names=[]
51
- for face_encoding in face_encodings:
52
- matches=face_recognition.compare_faces(known_face_encoding,face_encoding)
53
- name=""
54
- face_distance=face_recognition.face_distance(known_face_encoding,face_encoding)
55
- best_match_index=np.argmin(face_distance)
56
- if matches[best_match_index]:
57
- name=known_faces_names[best_match_index]
58
-
59
- face_names.append(name)
60
- if name in known_faces_names:
61
- if name in students:
62
- students.remove(name)
63
- print(students)
64
- current_time=now.strftime("%H-%M-%S")
65
- lnwriter.writerow([name,current_time,"Present"])
66
- cv2.imshow("attendence system",frame)
67
- if cv2.waitKey(1) & 0xFF==ord('q'):
 
 
 
68
  break
 
 
 
 
69
  video_capture.release()
70
  cv2.destroyAllWindows()
71
  f.close()
 
72
  if bytes_data is None:
73
- st.stop()
 
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
+ now = datetime.now()
27
+ current_date = now.strftime("%Y-%m-%d")
28
 
29
+ f = open(current_date + '.csv', 'w+', newline='')
30
+ lnwriter = csv.writer(f)
 
 
 
 
 
31
 
32
  ############################
33
  import io
34
  import streamlit as st
35
+ bytes_data = None
36
 
37
+ img_file_buffer = st.camera_input("Take a picture")
38
  if img_file_buffer is not None:
 
39
  while True:
40
+ _, frame = video_capture.read()
41
+
42
+ if frame is not None and frame.size > 0:
43
+ small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
44
+ rgb_small_frame = small_frame[:, :, ::-1]
45
+ if s:
46
+ face_locations = face_recognition.face_locations(rgb_small_frame)
47
+ face_encodings = face_recognition.face_encodings(small_frame, face_locations)
48
+ face_names = []
49
+ for face_encoding in face_encodings:
50
+ matches = face_recognition.compare_faces(known_face_encoding, face_encoding)
51
+ name = ""
52
+ face_distance = face_recognition.face_distance(known_face_encoding, face_encoding)
53
+ best_match_index = np.argmin(face_distance)
54
+ if matches[best_match_index]:
55
+ name = known_faces_names[best_match_index]
56
+
57
+ face_names.append(name)
58
+ if name in known_faces_names:
59
+ if name in students:
60
+ students.remove(name)
61
+ print(students)
62
+ current_time = now.strftime("%H-%M-%S")
63
+ lnwriter.writerow([name, current_time, "Present"])
64
+ cv2.imshow("attendance system", frame)
65
+ else:
66
+ print("Failed to retrieve frame from video capture.")
67
  break
68
+
69
+ if cv2.waitKey(1) & 0xFF == ord('q'):
70
+ break
71
+
72
  video_capture.release()
73
  cv2.destroyAllWindows()
74
  f.close()
75
+
76
  if bytes_data is None:
77
+ st.stop()