Vikas01 commited on
Commit
c458411
·
1 Parent(s): 8ff9a4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -69
app.py CHANGED
@@ -24,100 +24,101 @@ app = Flask(__name__)
24
 
25
  @app.route('/at')
26
  def testme():
27
- img_file_buffer=st.camera_input("Take a picture")
28
- if img_file_buffer is not None:
29
- test_image = Image.open(img_file_buffer)
30
- st.image(test_image, use_column_width=True)
31
- if bytes_data is None:
32
- st.stop()
 
33
 
34
- def attend():
35
- # Face recognition variables
36
- known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
37
- known_face_encodings = []
38
 
39
- # Load known face encodings
40
- sir_image = face_recognition.load_image_file("photos/sir.jpeg")
41
- sir_encoding = face_recognition.face_encodings(sir_image)[0]
42
 
43
- vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
44
- vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
45
 
46
- lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
47
- lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
48
 
49
- jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
50
- jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
51
 
52
- maam_image = face_recognition.load_image_file("photos/maam.png")
53
- maam_encoding = face_recognition.face_encodings(maam_image)[0]
54
 
55
- known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
56
 
57
- students = known_faces_names.copy()
58
 
59
- face_locations = []
60
- face_encodings = []
61
- face_names = []
62
 
63
- now = datetime.now()
64
- current_date = now.strftime("%Y-%m-%d")
65
- csv_file = open(f"{current_date}.csv", "a+", newline="")
66
 
67
- csv_writer = csv.writer(csv_file)
68
 
69
- # Function to run face recognition
70
- def run_face_recognition():
71
- video_capture = cv2.VideoCapture(0)
72
- s = True
73
 
74
- existing_names = set(row[0] for row in csv.reader(csv_file)) # Collect existing names from the CSV file
75
 
76
 
77
- while s:
78
- _, frame = video_capture.read()
79
- small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
80
- rgb_small_frame = small_frame[:, :, ::-1]
81
 
82
- face_locations = face_recognition.face_locations(rgb_small_frame)
83
- face_encodings = face_recognition.face_encodings(small_frame, face_locations)
84
- face_names = []
85
 
86
- for face_encoding in face_encodings:
87
- matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
88
- name = ""
89
- face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
90
- best_match_index = np.argmin(face_distance)
91
- if matches[best_match_index]:
92
- name = known_faces_names[best_match_index]
93
 
94
- face_names.append(name)
95
 
96
 
97
- for name in face_names:
98
- if name in known_faces_names and name in students and name not in existing_names:
99
- students.remove(name)
100
- print(students)
101
- print(f"Attendance recorded for {name}")
102
- current_time = now.strftime("%H-%M-%S")
103
- csv_writer.writerow([name, current_time, "Present"])
104
- existing_names.add(name) # Add the name to the set of existing names
105
 
106
- s = False # Set s to False to exit the loop after recording attendance
107
- break # Break the loop once attendance has been recorded for a name
108
 
109
- cv2.imshow("Attendance System", frame)
110
- if cv2.waitKey(1) & 0xFF == ord('q'):
111
- break
112
 
113
- video_capture.release()
114
- cv2.destroyAllWindows()
115
- csv_file.close()
116
 
117
- # Call the function to run face recognition
118
- run_face_recognition()
119
 
120
- return redirect(url_for('show_table'))
121
 
122
 
123
 
 
24
 
25
  @app.route('/at')
26
  def testme():
27
+ return "i am in testme"
28
+ # img_file_buffer=st.camera_input("Take a picture")
29
+ # if img_file_buffer is not None:
30
+ # test_image = Image.open(img_file_buffer)
31
+ # st.image(test_image, use_column_width=True)
32
+ # if bytes_data is None:
33
+ # st.stop()
34
 
35
+ # def attend():
36
+ # # Face recognition variables
37
+ # known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
38
+ # known_face_encodings = []
39
 
40
+ # # Load known face encodings
41
+ # sir_image = face_recognition.load_image_file("photos/sir.jpeg")
42
+ # sir_encoding = face_recognition.face_encodings(sir_image)[0]
43
 
44
+ # vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
45
+ # vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
46
 
47
+ # lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
48
+ # lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
49
 
50
+ # jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
51
+ # jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
52
 
53
+ # maam_image = face_recognition.load_image_file("photos/maam.png")
54
+ # maam_encoding = face_recognition.face_encodings(maam_image)[0]
55
 
56
+ # known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
57
 
58
+ # students = known_faces_names.copy()
59
 
60
+ # face_locations = []
61
+ # face_encodings = []
62
+ # face_names = []
63
 
64
+ # now = datetime.now()
65
+ # current_date = now.strftime("%Y-%m-%d")
66
+ # csv_file = open(f"{current_date}.csv", "a+", newline="")
67
 
68
+ # csv_writer = csv.writer(csv_file)
69
 
70
+ # # Function to run face recognition
71
+ # def run_face_recognition():
72
+ # video_capture = cv2.VideoCapture(0)
73
+ # s = True
74
 
75
+ # existing_names = set(row[0] for row in csv.reader(csv_file)) # Collect existing names from the CSV file
76
 
77
 
78
+ # while s:
79
+ # _, frame = video_capture.read()
80
+ # small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
81
+ # rgb_small_frame = small_frame[:, :, ::-1]
82
 
83
+ # face_locations = face_recognition.face_locations(rgb_small_frame)
84
+ # face_encodings = face_recognition.face_encodings(small_frame, face_locations)
85
+ # face_names = []
86
 
87
+ # for face_encoding in face_encodings:
88
+ # matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
89
+ # name = ""
90
+ # face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
91
+ # best_match_index = np.argmin(face_distance)
92
+ # if matches[best_match_index]:
93
+ # name = known_faces_names[best_match_index]
94
 
95
+ # face_names.append(name)
96
 
97
 
98
+ # for name in face_names:
99
+ # if name in known_faces_names and name in students and name not in existing_names:
100
+ # students.remove(name)
101
+ # print(students)
102
+ # print(f"Attendance recorded for {name}")
103
+ # current_time = now.strftime("%H-%M-%S")
104
+ # csv_writer.writerow([name, current_time, "Present"])
105
+ # existing_names.add(name) # Add the name to the set of existing names
106
 
107
+ # s = False # Set s to False to exit the loop after recording attendance
108
+ # break # Break the loop once attendance has been recorded for a name
109
 
110
+ # cv2.imshow("Attendance System", frame)
111
+ # if cv2.waitKey(1) & 0xFF == ord('q'):
112
+ # break
113
 
114
+ # video_capture.release()
115
+ # cv2.destroyAllWindows()
116
+ # csv_file.close()
117
 
118
+ # # Call the function to run face recognition
119
+ # run_face_recognition()
120
 
121
+ # return redirect(url_for('show_table'))
122
 
123
 
124