Format code
This commit is contained in:
parent
504ccb6695
commit
259cc8f200
|
@ -37,7 +37,7 @@ def main():
|
||||||
# It's taking up too many lines in this file
|
# It's taking up too many lines in this file
|
||||||
argparser = argparse.ArgumentParser(
|
argparser = argparse.ArgumentParser(
|
||||||
prog="Wyzely Detect",
|
prog="Wyzely Detect",
|
||||||
description="Recognize faces/objects in a video stream (from a webcam or a security camera) and send notifications to your devices", # noqa: E501
|
description="Recognize faces/objects in a video stream (from a webcam or a security camera) and send notifications to your devices", # noqa: E501
|
||||||
epilog=":)",
|
epilog=":)",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ def main():
|
||||||
if "FACES_DIRECTORY" in os.environ and os.environ["FACES_DIRECTORY"] != ""
|
if "FACES_DIRECTORY" in os.environ and os.environ["FACES_DIRECTORY"] != ""
|
||||||
else "faces",
|
else "faces",
|
||||||
type=str,
|
type=str,
|
||||||
help="The directory to store the faces. Can either contain images or subdirectories with images, the latter being the preferred method", # noqa: E501
|
help="The directory to store the faces. Can either contain images or subdirectories with images, the latter being the preferred method", # noqa: E501
|
||||||
)
|
)
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--detect-object",
|
"--detect-object",
|
||||||
|
@ -202,7 +202,7 @@ def main():
|
||||||
results = model(run_frame, verbose=False)
|
results = model(run_frame, verbose=False)
|
||||||
|
|
||||||
path_to_faces = Path(args.faces_directory)
|
path_to_faces = Path(args.faces_directory)
|
||||||
path_to_faces_exists = path_to_faces.is_dir()
|
path_to_faces_exists = path_to_faces.is_dir()
|
||||||
|
|
||||||
for i, r in enumerate(results):
|
for i, r in enumerate(results):
|
||||||
# list of dicts with each dict containing a label, x1, y1, x2, y2
|
# list of dicts with each dict containing a label, x1, y1, x2, y2
|
||||||
|
@ -216,8 +216,7 @@ def main():
|
||||||
# May be better to check every iteration, but this also works
|
# May be better to check every iteration, but this also works
|
||||||
if path_to_faces_exists:
|
if path_to_faces_exists:
|
||||||
if face_details := utils.recognize_face(
|
if face_details := utils.recognize_face(
|
||||||
path_to_directory=path_to_faces,
|
path_to_directory=path_to_faces, run_frame=run_frame
|
||||||
run_frame=run_frame
|
|
||||||
):
|
):
|
||||||
plot_boxes.append(face_details)
|
plot_boxes.append(face_details)
|
||||||
objects_and_peoples = notify.thing_detected(
|
objects_and_peoples = notify.thing_detected(
|
||||||
|
|
|
@ -102,11 +102,10 @@ def recognize_face(
|
||||||
print("representations_arcface.pkl does not exist")
|
print("representations_arcface.pkl does not exist")
|
||||||
first_face_try = False
|
first_face_try = False
|
||||||
|
|
||||||
|
|
||||||
# face_dataframes is a vanilla list of dataframes
|
# face_dataframes is a vanilla list of dataframes
|
||||||
# It seems face_dataframes is empty if the face database (directory) doesn't exist. Seems to work if it's empty though
|
# It seems face_dataframes is empty if the face database (directory) doesn't exist. Seems to work if it's empty though
|
||||||
# This line is here to prevent a crash if that happens. However, there is a check in __main__ so it shouldn't happen
|
# This line is here to prevent a crash if that happens. However, there is a check in __main__ so it shouldn't happen
|
||||||
face_dataframes = []
|
face_dataframes = []
|
||||||
try:
|
try:
|
||||||
face_dataframes = DeepFace.find(
|
face_dataframes = DeepFace.find(
|
||||||
run_frame,
|
run_frame,
|
||||||
|
@ -117,12 +116,13 @@ def recognize_face(
|
||||||
silent=True,
|
silent=True,
|
||||||
# Could use VGG-Face, but whilst fixing another issue, ArcFace seemed to be slightly faster
|
# Could use VGG-Face, but whilst fixing another issue, ArcFace seemed to be slightly faster
|
||||||
# I read somewhere that opencv is the fastest (but not as accurate). Could be changed later, but opencv seems to work well
|
# I read somewhere that opencv is the fastest (but not as accurate). Could be changed later, but opencv seems to work well
|
||||||
model_name="ArcFace", detector_backend="opencv"
|
model_name="ArcFace",
|
||||||
)
|
detector_backend="opencv",
|
||||||
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
if (
|
if (
|
||||||
str(e)
|
str(e)
|
||||||
== "Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False." # noqa: E501
|
== "Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False." # noqa: E501
|
||||||
):
|
):
|
||||||
# print("No faces recognized") # For debugging
|
# print("No faces recognized") # For debugging
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue