minor code readability changes
This commit is contained in:
parent
b8aa070600
commit
59e622c17d
3 changed files with 17 additions and 20 deletions
|
|
@ -15,7 +15,7 @@ except:
|
||||||
user = os.environ.get("SUDO_USER")
|
user = os.environ.get("SUDO_USER")
|
||||||
|
|
||||||
# If that fails, try to get the direct user
|
# If that fails, try to get the direct user
|
||||||
if user == "root" or user == None:
|
if user == "root" or user is None:
|
||||||
env_user = getpass.getuser().strip()
|
env_user = getpass.getuser().strip()
|
||||||
|
|
||||||
# If even that fails, error out
|
# If even that fails, error out
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import cv2
|
|
||||||
import configparser
|
import configparser
|
||||||
import builtins
|
import builtins
|
||||||
|
import cv2
|
||||||
|
|
||||||
# Try to import face_recognition and give a nice error if we can't
|
# Try to import face_recognition and give a nice error if we can't
|
||||||
# Add should be the first point where import issues show up
|
# Add should be the first point where import issues show up
|
||||||
|
|
@ -55,12 +55,12 @@ print("Adding face model for the user " + user)
|
||||||
label = "Initial model"
|
label = "Initial model"
|
||||||
|
|
||||||
# If models already exist, set that default label
|
# If models already exist, set that default label
|
||||||
if len(encodings) > 0:
|
if encodings:
|
||||||
label = "Model #" + str(len(encodings) + 1)
|
label = "Model #" + str(len(encodings) + 1)
|
||||||
|
|
||||||
# Keep de default name if we can't ask questions
|
# Keep de default name if we can't ask questions
|
||||||
if builtins.howdy_args.y:
|
if builtins.howdy_args.y:
|
||||||
print("Using default label \"" + label + "\" because of -y flag")
|
print('Using default label "%s" because of -y flag' % (label, ))
|
||||||
else:
|
else:
|
||||||
# Ask the user for a custom label
|
# Ask the user for a custom label
|
||||||
label_in = input("Enter a label for this new model [" + label + "]: ")
|
label_in = input("Enter a label for this new model [" + label + "]: ")
|
||||||
|
|
@ -119,11 +119,9 @@ while frames < 60:
|
||||||
enc = face_recognition.face_encodings(frame)
|
enc = face_recognition.face_encodings(frame)
|
||||||
|
|
||||||
# If we've found at least one, we can continue
|
# If we've found at least one, we can continue
|
||||||
if len(enc) > 0:
|
if enc:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
# If 0 faces are detected we can't continue
|
|
||||||
if len(enc) == 0:
|
|
||||||
print("No face detected, aborting")
|
print("No face detected, aborting")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,16 @@ dark_tries = 0
|
||||||
# Try to load the face model from the models folder
|
# Try to load the face model from the models folder
|
||||||
try:
|
try:
|
||||||
models = json.load(open(os.path.dirname(os.path.abspath(__file__)) + "/models/" + user + ".dat"))
|
models = json.load(open(os.path.dirname(os.path.abspath(__file__)) + "/models/" + user + ".dat"))
|
||||||
|
|
||||||
|
# Put all models together into 1 array
|
||||||
|
encodings = [model["data"] for model in models]
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sys.exit(10)
|
sys.exit(10)
|
||||||
|
|
||||||
# Check if the file contains a model
|
# Check if the file contains a model
|
||||||
if len(models) < 1:
|
if not encodings:
|
||||||
sys.exit(10)
|
sys.exit(10)
|
||||||
|
|
||||||
# Put all models together into 1 array
|
|
||||||
for model in models:
|
|
||||||
encodings += model["data"]
|
|
||||||
|
|
||||||
# Add the time needed to start the script
|
# Add the time needed to start the script
|
||||||
timings.append(time.time())
|
timings.append(time.time())
|
||||||
|
|
||||||
|
|
@ -153,7 +152,7 @@ while True:
|
||||||
if end_report:
|
if end_report:
|
||||||
def print_timing(label, offset):
|
def print_timing(label, offset):
|
||||||
"""Helper function to print a timing from the list"""
|
"""Helper function to print a timing from the list"""
|
||||||
print(" " + label + ": " + str(round((timings[1 + offset] - timings[offset]) * 1000)) + "ms")
|
print(" %s: %dms" % (label, round((timings[1 + offset] - timings[offset]) * 1000)))
|
||||||
|
|
||||||
print("Time spent")
|
print("Time spent")
|
||||||
print_timing("Starting up", 0)
|
print_timing("Starting up", 0)
|
||||||
|
|
@ -162,19 +161,19 @@ while True:
|
||||||
print_timing("Searching for known face", 3)
|
print_timing("Searching for known face", 3)
|
||||||
|
|
||||||
print("\nResolution")
|
print("\nResolution")
|
||||||
print(" Native: " + str(height) + "x" + str(width))
|
print(" Native: %dx%d" % (height, width))
|
||||||
print(" Used: " + str(scale_height) + "x" + str(scale_width))
|
print(" Used: %dx%d" % (scale_height, scale_width))
|
||||||
|
|
||||||
# Show the total number of frames and calculate the FPS by deviding it by the total scan time
|
# Show the total number of frames and calculate the FPS by deviding it by the total scan time
|
||||||
print("\nFrames searched: " + str(frames) + " (" + str(round(float(frames) / (timings[4] - timings[3]), 2)) + " fps)")
|
print("\nFrames searched: %d (%.2f fps)" % (frames, frames / (timings[4] - timings[3])))
|
||||||
print("Dark frames ignored: " + str(dark_tries))
|
print("Dark frames ignored: %d " % (dark_tries, ))
|
||||||
print("Certainty of winning frame: " + str(round(match * 10, 3)))
|
print("Certainty of winning frame: %.3f" % (match * 10, ))
|
||||||
|
|
||||||
# Catch older 3-encoding models
|
# Catch older 3-encoding models
|
||||||
if not match_index in models:
|
if not match_index in models:
|
||||||
match_index = 0
|
match_index = 0
|
||||||
|
|
||||||
print("Winning model: " + str(match_index) + " (\"" + models[match_index]["label"] + "\")")
|
print("Winning model: %d (\"%s\")" % (match_index, models[match_index]["label"]))
|
||||||
|
|
||||||
# End peacefully
|
# End peacefully
|
||||||
stop(0)
|
stop(0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue