Commit eb415628 authored by Kyle Anderson's avatar Kyle Anderson

Merge branch 'interface' into 'master'

Interface CLI

See merge request !4
parents e16a3ae8 6dd51d98
......@@ -23,7 +23,7 @@ def load_encodings(file_location: str):
return data_handler.load_database(file_location)
def determine_identity(face_encoding, known_faces):
def determine_identity(face_encoding, known_faces) -> str:
"""
"Determines the most likely identity of a single face. Returns the user id.
:param face_encoding: The encoding which needs identification.
......@@ -36,8 +36,10 @@ def determine_identity(face_encoding, known_faces):
# Count the number of occurrences of true.
recognized_users[user_id] = matches.count(True)
matched_user: str = max(recognized_users,
key=recognized_users.get)
matched_user = ""
if len(recognized_users) > 0:
matched_user: str = max(recognized_users,
key=recognized_users.get)
return matched_user
......
......@@ -6,7 +6,7 @@ DATA_DIR = "data"
DATASET_DIR = "dataset"
DATABASE_LOC = os.path.join(DATA_DIR, "database.pickle")
RES_DIRECTORY = "./res"
RES_DIRECTORY = "res"
# Directory for the face detection model.
FACE_DETECTION_MODEL_DIR = os.path.join(RES_DIRECTORY, "face_detection_model")
EMBEDDINGS_PROCESSOR_LOC = os.path.join(RES_DIRECTORY, "openface_nn4.small2.v1.t7")
......
......@@ -15,7 +15,8 @@ def authenticate_user(base_dir: str = os.getcwd()) -> str:
:param base_dir: The base directory, from which all default paths are relative. Defaults to current working directory.
:return: The user_id of the recognized user, or empty string if none was recognized.
"""
recognized = authenticate.recognize_user_from_database(database_loc=os.path.join(base_dir, common.DATA_DIR))
recognized = authenticate.recognize_user_from_database(
database_loc=os.path.join(base_dir, common.DATABASE_LOC))
return recognized if recognized is not None else ""
......@@ -25,5 +26,24 @@ def register_user(base_dir: str = os.getcwd()) -> None:
:param base_dir: The base directory, from which all default paths are relative. Defaults to current working directory.
:return: None
"""
register.register_users_and_save(directory_location=os.path.join(base_dir, common.DATASET_DIR),
register.register_users_and_save(directory_location=os.path.join(base_dir, common.DATABASE_LOC),
delete_images_on_complete=True, overwrite_data=False)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="API Interface Options")
parser.add_argument("--base-dir", type=str, required=False, default=None,
help="The directory from which the save locations should be relative.")
parser.add_argument("--authenticate", required=False, default=False, action="store_true",
help="Present this argument to authenticate a user.")
parser.add_argument("--register", required=False, default=False, action="store_true",
help="Present this argument to register a user.")
args = parser.parse_args()
kwargs = dict(base_dir=args.base_dir)
if args.register:
register_user(**{arg_name: arg for (arg_name, arg) in kwargs.items() if args is not None})
elif args.authenticate:
print(authenticate_user(**{arg_name: arg for (arg_name, arg) in kwargs.items() if arg is not None}))
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