Vikas01 commited on
Commit
a5b2a45
1 Parent(s): 593ec96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -55
app.py CHANGED
@@ -4,81 +4,74 @@ import numpy as np
4
  import csv
5
  from datetime import datetime
6
 
7
- # video_capture=cv2.VideoCapture(1)
8
- # if not video_capture.isOpened():
9
- # print("Failed to open the video capture.")
10
- # exit()
11
 
 
 
12
 
 
 
 
13
 
 
 
 
 
14
 
15
- sir_image=face_recognition.load_image_file("photos/sir.jpeg")
16
- sir_encoding=face_recognition.face_encodings(sir_image)[0]
17
 
18
- vikas_image=face_recognition.load_image_file("photos/vikas.jpg")
19
- vikas_encoding=face_recognition.face_encodings(vikas_image)[0]
20
 
21
- known_face_encoding=[sir_encoding,vikas_encoding]
22
-
23
- known_faces_names=["Sarwan Sir","Vikas"]
24
-
25
- students=known_faces_names.copy()
26
-
27
- face_locations=[]
28
- face_encodings=[]
29
- face_names=[]
30
- s=True
31
-
32
-
33
-
34
- now=datetime.now()
35
- current_date=now.strftime("%Y-%m-%d")
36
-
37
-
38
- f=open(current_date+'.csv','w+',newline='')
39
- lnwriter=csv.writer(f)
40
-
41
- ############################
42
  import io
43
  import streamlit as st
44
- bytes_data=None
45
-
46
- run=st.checkbox('Run')
47
- FRAME_WINDOW=st.image([])
48
- camera=cv2.VideoCapture(0)
49
-
50
-
51
 
 
52
 
 
 
 
53
 
54
  while run:
55
- _,frame=camera.read()
56
- frame=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
57
- # FRAME_WINDOW.image(frame)
58
- small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
59
- rgb_small_frame=small_frame[:,:,::-1]
 
 
 
 
60
  if s:
61
- face_locations=face_recognition.face_locations(rgb_small_frame)
62
  face_encodings = face_recognition.face_encodings(small_frame, face_locations)
63
- face_names=[]
 
64
  for face_encoding in face_encodings:
65
- matches=face_recognition.compare_faces(known_face_encoding,face_encoding)
66
- name=""
67
- face_distance=face_recognition.face_distance(known_face_encoding,face_encoding)
68
- best_match_index=np.argmin(face_distance)
 
69
  if matches[best_match_index]:
70
- name=known_faces_names[best_match_index]
71
 
72
  face_names.append(name)
 
73
  if name in known_faces_names:
74
  if name in students:
75
  students.remove(name)
76
  print(students)
77
- current_time=now.strftime("%H-%M-%S")
78
- lnwriter.writerow([name,current_time,"Present"])
79
- cv2.imshow("attendence system",frame)
80
- if cv2.waitKey(1) & 0xFF==ord('q'):
 
 
81
  break
82
- else:
83
- st.write('Stopped')
84
- f.close()
 
 
4
  import csv
5
  from datetime import datetime
6
 
7
+ sir_image = face_recognition.load_image_file("photos/sir.jpeg")
8
+ sir_encoding = face_recognition.face_encodings(sir_image)[0]
 
 
9
 
10
+ vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
11
+ vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
12
 
13
+ known_face_encoding = [sir_encoding, vikas_encoding]
14
+ known_faces_names = ["Sarwan Sir", "Vikas"]
15
+ students = known_faces_names.copy()
16
 
17
+ face_locations = []
18
+ face_encodings = []
19
+ face_names = []
20
+ s = True
21
 
22
+ now = datetime.now()
23
+ current_date = now.strftime("%Y-%m-%d")
24
 
25
+ f = open(current_date + '.csv', 'w+', newline='')
26
+ lnwriter = csv.writer(f)
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  import io
29
  import streamlit as st
 
 
 
 
 
 
 
30
 
31
+ bytes_data = None
32
 
33
+ run = st.checkbox('Run')
34
+ FRAME_WINDOW = st.image([])
35
+ camera = cv2.VideoCapture(0)
36
 
37
  while run:
38
+ _, frame = camera.read()
39
+
40
+ if frame is None:
41
+ continue
42
+
43
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
44
+ small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
45
+ rgb_small_frame = small_frame[:, :, ::-1]
46
+
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
+
52
  for face_encoding in face_encodings:
53
+ matches = face_recognition.compare_faces(known_face_encoding, face_encoding)
54
+ name = ""
55
+ face_distance = face_recognition.face_distance(known_face_encoding, face_encoding)
56
+ best_match_index = np.argmin(face_distance)
57
+
58
  if matches[best_match_index]:
59
+ name = known_faces_names[best_match_index]
60
 
61
  face_names.append(name)
62
+
63
  if name in known_faces_names:
64
  if name in students:
65
  students.remove(name)
66
  print(students)
67
+ current_time = now.strftime("%H-%M-%S")
68
+ lnwriter.writerow([name, current_time, "Present"])
69
+
70
+ cv2.imshow("attendance system", frame)
71
+
72
+ if cv2.waitKey(1) & 0xFF == ord('q'):
73
  break
74
+ else:
75
+ st.write('Stopped')
76
+
77
+ f.close()