Commit a5745728 authored by Kyle Anderson's avatar Kyle Anderson

Small refactorings

Just did some small refactorings on some of the files.
parent 92ff71a8
......@@ -38,21 +38,20 @@ def determine_identity(face_encoding, known_faces):
"""Determines the most likely identity of a single face. Returns the user id."""
matches = face_recognition.compare_faces(
known_faces["encodings"], face_encoding)
matched_user = None
matched_user = ''
matched_user_id_count = {}
# If there is at least one match to a face in the database, figure out which one it is.
if True in matches:
matched_user_id_count = {}
matched_users = [user_index for (
user_index, is_match) in enumerate(matches) if is_match]
for i in matched_users:
user_id: str = known_faces["user_ids"][i]
matched_user_id_count[user_id] = matched_user_id_count.get(
user_id, 0) + 1
matched_user_id_count[user_id] = matched_user_id_count.get(user_id, 0) + 1
matched_user: str = max(matched_user_id_count,
return matched_user
......@@ -65,6 +64,7 @@ def check_recognized_users(recognized_user_counts):
return recognized_users
def draw_rectanges_and_user_ids(image_frame, conversion: float, boxes, user_ids: list):
"""Draws the rectangles and user_ids onto the video stream so anyone viewing the stream could see them."""
for ((top, right, bottom, left), user_id) in zip(boxes, user_ids):
......@@ -80,6 +80,7 @@ def draw_rectanges_and_user_ids(image_frame, conversion: float, boxes, user_ids:
cv2.putText(image_frame, user_id, (left, y), cv2.FONT_HERSHEY_PLAIN, 0.75, (0, 255, 0), 2)
def display_frame(frame):
"""Displays the frame to the user."""
cv2.imshow("Frame", frame)
......@@ -98,8 +99,8 @@ def recognize_user():
# 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 and not user_recognized):
# Read a image_frame from the videostream.
while time.time() < timeout_time and not user_recognized:
# Read a image_frame from the video stream.
image_frame =
# Convert input from BGR to RGB
......@@ -130,7 +131,7 @@ def recognize_user():
recognized_user = max(recognized_users_count,
if recognized_users_count[recognized_user] < MIN_USER_RECOGNITION_COUNT:
recognized_user = None
return recognized_user
Creates a facial recognition profile for a new user.
Creates a facial recongnition profile for a new user.
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