Shafeek Saleem commited on
Commit
8345b1c
1 Parent(s): 719fca4
Files changed (2) hide show
  1. pages/4_Trying It Out.py +1 -1
  2. utils/inference.py +8 -11
pages/4_Trying It Out.py CHANGED
@@ -32,7 +32,7 @@ def step4_page():
32
  st.info("Select your input type to analyze!")
33
  input_type = st.radio("Select the Input Type", ["Image upload", "Camera"])
34
  # Put slide to adjust tolerance
35
- tolerance = 0.14
36
  # tolerance = st.slider("Tolerance", 0.0, 1.0, 0.15, 0.01)
37
  # st.info(
38
  # "Tolerance is the threshold for face recognition. The lower the tolerance, the more strict the face recognition. The higher the tolerance, the more loose the face recognition.")
 
32
  st.info("Select your input type to analyze!")
33
  input_type = st.radio("Select the Input Type", ["Image upload", "Camera"])
34
  # Put slide to adjust tolerance
35
+ tolerance = 0.2
36
  # tolerance = st.slider("Tolerance", 0.0, 1.0, 0.15, 0.01)
37
  # st.info(
38
  # "Tolerance is the threshold for face recognition. The lower the tolerance, the more strict the face recognition. The higher the tolerance, the more loose the face recognition.")
utils/inference.py CHANGED
@@ -16,23 +16,20 @@ def recognize(image,tolerance):
16
  face_locations = face_recognition.face_locations(image)
17
  face_encodings = face_recognition.face_encodings(image,face_locations)
18
  for (top,right,bottom,left), face_encoding in zip(face_locations,face_encodings):
19
- st.write("face_encoding")
20
- st.write(face_encoding.shape)
21
- st.write("known_encoding")
22
- st.write(len(known_encoding))
23
- st.write(known_encoding[0].shape)
24
  matches = face_recognition.compare_faces(known_encoding,face_encoding,tolerance=tolerance)
25
- # distance = face_recognition.face_distance(known_encoding,face_encoding)
26
  name = 'Unknown'
27
  face_id = 'Unknown'
 
28
  for i in range(len(matches)):
29
  if matches[i].all():
30
  match_index = i
31
- name = database[match_index]['name']
32
- face_id = database[match_index]['face_id'].split("_")[1]
33
- # distance = round(np.sum(distance[match_index]),2)
34
- # cv2.putText(image,str(distance),(left,top-30),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
35
- break
 
36
  cv2.rectangle(image,(left,top),(right,bottom),(0,255,0),2)
37
  cv2.putText(image,name,(left,top-10),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
38
  return image, name, face_id
 
16
  face_locations = face_recognition.face_locations(image)
17
  face_encodings = face_recognition.face_encodings(image,face_locations)
18
  for (top,right,bottom,left), face_encoding in zip(face_locations,face_encodings):
 
 
 
 
 
19
  matches = face_recognition.compare_faces(known_encoding,face_encoding,tolerance=tolerance)
20
+ distances = face_recognition.face_distance(known_encoding,face_encoding)
21
  name = 'Unknown'
22
  face_id = 'Unknown'
23
+ distance = 100000
24
  for i in range(len(matches)):
25
  if matches[i].all():
26
  match_index = i
27
+ temp_dist = round(np.sum(distances[match_index]),2)
28
+ if temp_dist < distance:
29
+ distance = temp_dist
30
+ name = database[match_index]['name']
31
+ face_id = database[match_index]['face_id'].split("_")[1]
32
+ # cv2.putText(image,str(distance),(left,top-30),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
33
  cv2.rectangle(image,(left,top),(right,bottom),(0,255,0),2)
34
  cv2.putText(image,name,(left,top-10),cv2.FONT_HERSHEY_SIMPLEX,0.75,(0,255,0),2)
35
  return image, name, face_id