Commit 5d0be5d9 authored by Kyle Anderson's avatar Kyle Anderson

Fix problem with authenticate user allowing anyone entry

The authenticate user script was letting anyone in, so have now fixed that hopefully. Still awaiting final testing.
parent 6dd51d98
......@@ -33,8 +33,10 @@ def determine_identity(face_encoding, known_faces) -> str:
recognized_users = {}
for (user_id, user_encodings) in known_faces.items():
matches = face_recognition.compare_faces(user_encodings, face_encoding)
count = matches.count(True)
if count > 0:
# Count the number of occurrences of true.
recognized_users[user_id] = matches.count(True)
recognized_users[user_id] = count
matched_user = ""
if len(recognized_users) > 0:
......@@ -70,27 +72,14 @@ def draw_rectangles_and_user_ids(image_frame, conversion: float, box_user_id_map
common.display_frame(image_frame)
def recognize_user(known_faces: dict, encoding_model: str = "hog", image_flip: int = None,
draw_rectangles=False):
"""Attempts to recognize a user.
Returns the ID of the user if identified, or None if no users are identified."""
recognized_users_count = {}
recognized_user = None
video_stream = common.start_video_stream(0)
# Determine the time at which we will time out. Equal to current time + timeout.
timeout_time: float = time.time() + TIMEOUT
while time.time() < timeout_time:
# Read a image_frame from the video stream.
ret, image_frame = video_stream.read()
if image_flip is not None:
image_frame = cv2.flip(image_frame, image_flip)
def run_face_recognition(frame, known_faces: dict, encoding_model: str = "hog", draw_rectangles: bool = False) -> list:
recognized_user_ids: list = []
# Convert input from BGR to RGB
cv2.cvtColor(image_frame, cv2.COLOR_BGR2RGB)
cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Resize image to width of 750 PX to speed up processing.
rgb_image = imutils.resize(image_frame, width=750)
r = image_frame.shape[1] / float(rgb_image.shape[1])
rgb_image = imutils.resize(frame, width=750)
r = frame.shape[1] / float(rgb_image.shape[1])
# Detect the location of each face and determine the boxes in which they lie
boxes = face_recognition.face_locations(
......@@ -103,13 +92,37 @@ def recognize_user(known_faces: dict, encoding_model: str = "hog", image_flip: i
for (i, encoding) in enumerate(encodings):
user_id: str = determine_identity(encoding, known_faces)
if user_id:
if user_id not in recognized_users_count:
recognized_users_count[user_id] = 0
recognized_users_count[user_id] += 1
box_user_id_mapping[boxes[i]] = user_id
recognized_user_ids.append(user_id)
if draw_rectangles:
draw_rectangles_and_user_ids(image_frame, r, box_user_id_mapping)
draw_rectangles_and_user_ids(frame, r, box_user_id_mapping)
return recognized_user_ids
def recognize_user(known_faces: dict, encoding_model: str = "hog", image_flip: int = None,
draw_rectangles: bool = False):
"""Attempts to recognize a user.
Returns the ID of the user if identified, or None if no users are identified."""
recognized_users_count = {}
recognized_user = None
video_stream = common.start_video_stream(0)
# Determine the time at which we will time out. Equal to current time + timeout.
timeout_time: float = time.time() + TIMEOUT
while time.time() < timeout_time:
# Read a image_frame from the video stream.
ret, image_frame = video_stream.read()
if image_flip is not None:
image_frame = cv2.flip(image_frame, image_flip)
recognized_user_ids = run_face_recognition(image_frame, known_faces, encoding_model=encoding_model,
draw_rectangles=draw_rectangles)
for user_id in recognized_user_ids:
if user_id not in recognized_users_count:
recognized_users_count[user_id] = 0
recognized_users_count[user_id] += 1
# Now check if we have already positively identified a user enough times
recognized_users = check_recognized_users(recognized_users_count)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment