Shafeek Saleem commited on
Commit
527b1c1
1 Parent(s): df175b2
Files changed (1) hide show
  1. pages/4_Face Recognition.py +21 -22
pages/4_Face Recognition.py CHANGED
@@ -30,7 +30,6 @@ def step4_page():
30
  )
31
  face_encodings_dir = os.path.join(".sessions", get_login()["username"], "face_encodings")
32
  face_encodings = os.listdir(face_encodings_dir)
33
- st.write(face_encodings)
34
  known_face_encodings = []
35
  known_face_names = []
36
  if len(face_encodings) > 0:
@@ -52,33 +51,33 @@ def step4_page():
52
  face_locations = face_recognition.face_locations(image)
53
  face_encodings = face_recognition.face_encodings(image, face_locations)
54
 
 
55
  # Loop through each face in this image
56
  cols = st.columns(len(face_encodings))
57
  i = 0
58
- st.image(image)
59
- st.info("Select the tolerance level you want for your model! (How much distance between faces to consider it a match. "
60
- "Lower is more strict. 0.6 is typical best performance.)")
61
- tolerance = st.slider('Select tolerance level', 0.0, 1.0, 0.3, 0.1)
62
- if tolerance:
63
- for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
64
- # See if the face is a match for the known face(s)
65
- # matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
66
 
67
- name = "Unknown"
68
- # If a match was found in known_face_encodings, just use the first one.
69
- face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
70
 
71
- # Calculate the row sums
72
- row_sums = np.sum(face_distances, axis=1)
73
- best_match_index = np.argmin(row_sums)
74
- if best_match_index is not None:
75
- name = known_face_names[best_match_index]
76
 
77
- face_image = image[top:bottom, left:right]
78
- pil_image = Image.fromarray(face_image)
79
- cols[i].image(pil_image, use_column_width=True)
80
- cols[i].write("Person name: " +name)
81
- i+=1
82
 
83
  st.info("Click on the button below to complete this level!")
84
  if st.button("Complete Level"):
 
30
  )
31
  face_encodings_dir = os.path.join(".sessions", get_login()["username"], "face_encodings")
32
  face_encodings = os.listdir(face_encodings_dir)
 
33
  known_face_encodings = []
34
  known_face_names = []
35
  if len(face_encodings) > 0:
 
51
  face_locations = face_recognition.face_locations(image)
52
  face_encodings = face_recognition.face_encodings(image, face_locations)
53
 
54
+ st.image(image)
55
  # Loop through each face in this image
56
  cols = st.columns(len(face_encodings))
57
  i = 0
58
+ # st.info("Select the tolerance level you want for your model! (How much distance between faces to consider it a match. "
59
+ # "Lower is more strict. 0.6 is typical best performance.)")
60
+ # tolerance = st.slider('Select tolerance level', 0.0, 1.0, 0.3, 0.1)
61
+ # if tolerance:
62
+ for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
63
+ # See if the face is a match for the known face(s)
64
+ # matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
 
65
 
66
+ name = "Unknown"
67
+ # If a match was found in known_face_encodings, just use the first one.
68
+ face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
69
 
70
+ # Calculate the row sums
71
+ row_sums = np.sum(face_distances, axis=1)
72
+ best_match_index = np.argmin(row_sums)
73
+ if best_match_index is not None:
74
+ name = known_face_names[best_match_index]
75
 
76
+ face_image = image[top:bottom, left:right]
77
+ pil_image = Image.fromarray(face_image)
78
+ cols[i].image(pil_image, use_column_width=True)
79
+ cols[i].write("Person name: " +name)
80
+ i+=1
81
 
82
  st.info("Click on the button below to complete this level!")
83
  if st.button("Complete Level"):