mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
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")
|
||||
|
||||
# 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()
|
||||
|
||||
# If even that fails, error out
|
||||
|
|
|
@ -5,9 +5,9 @@ import time
|
|||
import os
|
||||
import sys
|
||||
import json
|
||||
import cv2
|
||||
import configparser
|
||||
import builtins
|
||||
import cv2
|
||||
|
||||
# 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
|
||||
|
@ -55,12 +55,12 @@ print("Adding face model for the user " + user)
|
|||
label = "Initial model"
|
||||
|
||||
# If models already exist, set that default label
|
||||
if len(encodings) > 0:
|
||||
if encodings:
|
||||
label = "Model #" + str(len(encodings) + 1)
|
||||
|
||||
# Keep de default name if we can't ask questions
|
||||
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:
|
||||
# Ask the user for a custom 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)
|
||||
|
||||
# If we've found at least one, we can continue
|
||||
if len(enc) > 0:
|
||||
if enc:
|
||||
break
|
||||
|
||||
# If 0 faces are detected we can't continue
|
||||
if len(enc) == 0:
|
||||
else:
|
||||
print("No face detected, aborting")
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -42,17 +42,16 @@ dark_tries = 0
|
|||
# Try to load the face model from the models folder
|
||||
try:
|
||||
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:
|
||||
sys.exit(10)
|
||||
|
||||
# Check if the file contains a model
|
||||
if len(models) < 1:
|
||||
if not encodings:
|
||||
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
|
||||
timings.append(time.time())
|
||||
|
||||
|
@ -153,7 +152,7 @@ while True:
|
|||
if end_report:
|
||||
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(" %s: %dms" % (label, round((timings[1 + offset] - timings[offset]) * 1000)))
|
||||
|
||||
print("Time spent")
|
||||
print_timing("Starting up", 0)
|
||||
|
@ -162,19 +161,19 @@ while True:
|
|||
print_timing("Searching for known face", 3)
|
||||
|
||||
print("\nResolution")
|
||||
print(" Native: " + str(height) + "x" + str(width))
|
||||
print(" Used: " + str(scale_height) + "x" + str(scale_width))
|
||||
print(" Native: %dx%d" % (height, 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
|
||||
print("\nFrames searched: " + str(frames) + " (" + str(round(float(frames) / (timings[4] - timings[3]), 2)) + " fps)")
|
||||
print("Dark frames ignored: " + str(dark_tries))
|
||||
print("Certainty of winning frame: " + str(round(match * 10, 3)))
|
||||
print("\nFrames searched: %d (%.2f fps)" % (frames, frames / (timings[4] - timings[3])))
|
||||
print("Dark frames ignored: %d " % (dark_tries, ))
|
||||
print("Certainty of winning frame: %.3f" % (match * 10, ))
|
||||
|
||||
# Catch older 3-encoding models
|
||||
if not match_index in models:
|
||||
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
|
||||
stop(0)
|
||||
|
|
Loading…
Reference in a new issue