Vikas01 commited on
Commit
24f3950
·
1 Parent(s): 7782bb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -30
app.py CHANGED
@@ -80,47 +80,50 @@ def attend():
80
  def run_face_recognition():
81
  img_file_buffer=st.camera_input("Take a picture")
82
  if img_file_buffer is not None:
 
 
 
83
 
84
- s = True
85
 
86
- existing_names = set(row[0] for row in csv.reader(csv_file)) # Collect existing names from the CSV file
87
 
88
 
89
- while s:
90
- _, frame = img_file_buffer.read()
91
- small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
92
- rgb_small_frame = small_frame[:, :, ::-1]
93
 
94
- face_locations = face_recognition.face_locations(rgb_small_frame)
95
- face_encodings = face_recognition.face_encodings(small_frame, face_locations)
96
- face_names = []
97
 
98
- for face_encoding in face_encodings:
99
- matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
100
- name = ""
101
- face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
102
- best_match_index = np.argmin(face_distance)
103
- if matches[best_match_index]:
104
- name = known_faces_names[best_match_index]
105
 
106
- face_names.append(name)
107
 
108
 
109
- for name in face_names:
110
- if name in known_faces_names and name in students and name not in existing_names:
111
- students.remove(name)
112
- print(students)
113
- print(f"Attendance recorded for {name}")
114
- current_time = now.strftime("%H-%M-%S")
115
- csv_writer.writerow([name, current_time, "Present"])
116
- existing_names.add(name) # Add the name to the set of existing names
117
 
118
- s = False # Set s to False to exit the loop after recording attendance
119
- break # Break the loop once attendance has been recorded for a name
120
 
121
- cv2.imshow("Attendance System", frame)
122
- if cv2.waitKey(1) & 0xFF == ord('q'):
123
- break
124
  if bytes_data is None:
125
  st.stop()
126
  # video_capture.release()
 
80
  def run_face_recognition():
81
  img_file_buffer=st.camera_input("Take a picture")
82
  if img_file_buffer is not None:
83
+
84
+ test_image = Image.open(img_file_buffer)
85
+ st.image(test_image, use_column_width=True)
86
 
87
+ # s = True
88
 
89
+ # existing_names = set(row[0] for row in csv.reader(csv_file)) # Collect existing names from the CSV file
90
 
91
 
92
+ # while s:
93
+ # _, frame = img_file_buffer.read()
94
+ # small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
95
+ # rgb_small_frame = small_frame[:, :, ::-1]
96
 
97
+ # face_locations = face_recognition.face_locations(rgb_small_frame)
98
+ # face_encodings = face_recognition.face_encodings(small_frame, face_locations)
99
+ # face_names = []
100
 
101
+ # for face_encoding in face_encodings:
102
+ # matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
103
+ # name = ""
104
+ # face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
105
+ # best_match_index = np.argmin(face_distance)
106
+ # if matches[best_match_index]:
107
+ # name = known_faces_names[best_match_index]
108
 
109
+ # face_names.append(name)
110
 
111
 
112
+ # for name in face_names:
113
+ # if name in known_faces_names and name in students and name not in existing_names:
114
+ # students.remove(name)
115
+ # print(students)
116
+ # print(f"Attendance recorded for {name}")
117
+ # current_time = now.strftime("%H-%M-%S")
118
+ # csv_writer.writerow([name, current_time, "Present"])
119
+ # existing_names.add(name) # Add the name to the set of existing names
120
 
121
+ # s = False # Set s to False to exit the loop after recording attendance
122
+ # break # Break the loop once attendance has been recorded for a name
123
 
124
+ # cv2.imshow("Attendance System", frame)
125
+ # if cv2.waitKey(1) & 0xFF == ord('q'):
126
+ # break
127
  if bytes_data is None:
128
  st.stop()
129
  # video_capture.release()