Added clear command and requred sudo
This commit is contained in:
parent
b55f20c0e0
commit
84889c2785
6 changed files with 76 additions and 29 deletions
20
cli.py
20
cli.py
|
|
@ -1,15 +1,31 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
|
||||
if (len(sys.argv) == 1):
|
||||
if (len(sys.argv) < 3):
|
||||
print("Howdy IR face recognition help")
|
||||
import cli.help
|
||||
sys.exit()
|
||||
|
||||
cmd = sys.argv[1]
|
||||
user = sys.argv[1]
|
||||
cmd = sys.argv[2]
|
||||
|
||||
if cmd in ["list", "add", "remove", "clear"] and os.getenv("SUDO_USER") is None:
|
||||
print("Please run this command with sudo")
|
||||
sys.exit()
|
||||
|
||||
if cmd == "list":
|
||||
import cli.list
|
||||
elif cmd == "help":
|
||||
print("Howdy IR face recognition")
|
||||
import cli.help
|
||||
elif cmd == "add":
|
||||
import cli.add
|
||||
elif cmd == "clear":
|
||||
import cli.clear
|
||||
else:
|
||||
if sys.argv[1] in ["list", "add", "remove", "clear", "help"]:
|
||||
print("Usage: howdy <user> <command>")
|
||||
else:
|
||||
print('Unknown command "' + cmd + '"')
|
||||
import cli.help
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ def captureFrame(delay):
|
|||
insert_model["data"].append(clean_enc)
|
||||
|
||||
# The current user
|
||||
user = os.environ.get("USER")
|
||||
user = sys.argv[1]
|
||||
# The name of the tmp frame file to user
|
||||
tmp_file = "/tmp/howdy_" + user + ".jpg"
|
||||
# The permanent file to store the encoded model in
|
||||
|
|
|
|||
25
cli/clear.py
Normal file
25
cli/clear.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
# Get the full path to this file
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
# Get the passed user
|
||||
user = sys.argv[1]
|
||||
|
||||
if not os.path.exists(path + "/../models"):
|
||||
print("No models created yet, can't clear them if they don't exist")
|
||||
sys.exit()
|
||||
|
||||
if not os.path.isfile(path + "/../models/" + user + ".dat"):
|
||||
print(user + " has no models or they have been cleared already")
|
||||
sys.exit()
|
||||
|
||||
print("This will clear all models for " + user)
|
||||
ans = input("Do you want to continue [y/N]: ")
|
||||
|
||||
if (ans.lower() != "y"):
|
||||
print('\nInerpeting as a "NO"')
|
||||
sys.exit()
|
||||
|
||||
os.remove(path + "/../models/" + user + ".dat")
|
||||
print("\nModels cleared")
|
||||
24
cli/help.py
24
cli/help.py
|
|
@ -1,14 +1,14 @@
|
|||
print("Howdy IR face recognition\n")
|
||||
print("""
|
||||
Usage:
|
||||
howdy <user> <command> [argument]
|
||||
|
||||
print("Usage:")
|
||||
print(" howdy <command> [argument]\n")
|
||||
Commands:
|
||||
help Show this help page
|
||||
list List all saved face models for the current user
|
||||
add Add a new face model for the current user
|
||||
remove [id] Remove a specific model
|
||||
clear Remove all face models for the current user
|
||||
|
||||
print("Commands:")
|
||||
print(" help Show this help page")
|
||||
print(" list List all saved face models for the current user")
|
||||
print(" add Add a new face model for the current user")
|
||||
print(" remove [id] Remove a specific model")
|
||||
print(" clear Remove all face models for the current user")
|
||||
|
||||
print("\nFor support please visit")
|
||||
print("https://github.com/Boltgolt/howdy")
|
||||
For support please visit
|
||||
https://github.com/Boltgolt/howdy\
|
||||
""")
|
||||
|
|
|
|||
|
|
@ -4,20 +4,20 @@ import json
|
|||
import time
|
||||
|
||||
path = os.path.dirname(os.path.realpath(__file__)) + "/.."
|
||||
user = sys.argv[1]
|
||||
|
||||
if not os.path.exists(path + "/models"):
|
||||
print("Face models have not been initialized yet, please run:")
|
||||
print("\n\thowdy add\n")
|
||||
print("\n\thowdy " + user + " add\n")
|
||||
sys.exit(1)
|
||||
|
||||
user = os.environ.get("USER")
|
||||
enc_file = path + "/models/" + user + ".dat"
|
||||
|
||||
try:
|
||||
encodings = json.load(open(enc_file))
|
||||
except FileNotFoundError:
|
||||
print("No face model known for the current user (" + user + "), please run:")
|
||||
print("\n\thowdy add\n")
|
||||
print("No face model known for the user " + user + ", please run:")
|
||||
print("\n\thowdy " + user + " add\n")
|
||||
sys.exit(1)
|
||||
|
||||
print("Known face models for " + user + ":")
|
||||
|
|
|
|||
26
compare.py
26
compare.py
|
|
@ -13,10 +13,6 @@ import configparser
|
|||
# Start timing
|
||||
timings = [time.time()]
|
||||
|
||||
# Import face recognition, takes some time
|
||||
import face_recognition
|
||||
timings.append(time.time())
|
||||
|
||||
# Read config from disk
|
||||
config = configparser.ConfigParser()
|
||||
config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini")
|
||||
|
|
@ -56,6 +52,11 @@ if len(models) < 1:
|
|||
for model in models:
|
||||
encodings += model["data"]
|
||||
|
||||
# Import face recognition, takes some time
|
||||
timings.append(time.time())
|
||||
import face_recognition
|
||||
timings.append(time.time())
|
||||
|
||||
# Start video capture on the IR camera
|
||||
video_capture = cv2.VideoCapture(int(config.get("video", "device_id")))
|
||||
timings.append(time.time())
|
||||
|
|
@ -90,13 +91,18 @@ while True:
|
|||
if config.get("debug", "end_report") == "true":
|
||||
print("DEBUG END REPORT\n")
|
||||
|
||||
print("Time spend")
|
||||
print(" Importing face_recognition: " + str(round((timings[1] - timings[0]) * 1000)) + "ms")
|
||||
print(" Opening the camera: " + str(round((timings[2] - timings[1]) * 1000)) + "ms")
|
||||
print(" Searching for known face: " + str(round((timings[3] - timings[2]) * 1000)) + "ms\n")
|
||||
def print_timing(label, offset):
|
||||
"""Helper function to print a timing from the list"""
|
||||
print(" " + label + ": " + str(round((timings[1 + offset] - timings[offset]) * 1000)) + "ms")
|
||||
|
||||
print("Frames searched: " + str(frames))
|
||||
print("Certainty winning frame: " + str(round(match * 10, 3)))
|
||||
print("Time spend")
|
||||
print_timing("Starting up", 0)
|
||||
print_timing("Importing face_recognition", 1)
|
||||
print_timing("Opening the camera", 2)
|
||||
print_timing("Searching for known face", 3)
|
||||
|
||||
print("\nFrames searched: " + str(frames) + " (" + str(round(float(frames) / (timings[4] - timings[2]), 2)) + " fps)")
|
||||
print("Certainty of winning frame: " + str(round(match * 10, 3)))
|
||||
|
||||
exposures = ["long", "medium", "short"]
|
||||
model_id = math.floor(float(match_index) / 3)
|
||||
|
|
|
|||
Loading…
Reference in a new issue