From d7f85102264c0340f77b0bd1bc3f13ffa9003af0 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Tue, 13 Feb 2018 22:49:29 +0100 Subject: [PATCH] Timeouts are now by seconds and added max_height --- compare.py | 22 +++++++++++++++++++--- config.ini | 8 ++++++-- installer.py | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/compare.py b/compare.py index d075aa2..6c5adc4 100644 --- a/compare.py +++ b/compare.py @@ -61,6 +61,9 @@ timings.append(time.time()) video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) timings.append(time.time()) +# Fetch the max frame height +max_height = int(config.get("video", "max_height")) + # Start the read loop frames = 0 while True: @@ -70,6 +73,17 @@ while True: # Don't remove ret, it doesn't work without it ret, frame = video_capture.read() + height, width = frame.shape[:2] + + if max_height < height: + scaling_factor = max_height / float(height) + frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) + + scale_height, scale_width = frame.shape[:2] + + # Convert from BGR to RGB + frame = frame[:, :, ::-1] + # Get all faces from that frame as encodings face_encodings = face_recognition.face_encodings(frame) @@ -89,8 +103,6 @@ while True: # If set to true in the config, print debug text if config.get("debug", "end_report") == "true": - print("DEBUG END REPORT\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") @@ -101,6 +113,10 @@ while True: print_timing("Opening the camera", 2) 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("\nFrames searched: " + str(frames) + " (" + str(round(float(frames) / (timings[4] - timings[2]), 2)) + " fps)") print("Certainty of winning frame: " + str(round(match * 10, 3))) @@ -113,7 +129,7 @@ while True: stop(0) # Stop if we've exceded the maximum retry count - if tries > int(config.get("video", "frame_count")): + if time.time() - timings[3] > int(config.get("video", "timout")): stop(11) tries += 1 diff --git a/config.ini b/config.ini index 428b68f..a019e35 100644 --- a/config.ini +++ b/config.ini @@ -11,13 +11,17 @@ suppress_unknown = false # On a scale from 1 to 10, values above 5 are not recommended certainty = 3.5 -# The number of frames to capture and to process before timing out -frame_count = 30 +# The number of seconds to search before timing out +timout = 4 # The /dev/videoX id to capture frames from # Should be set automatically by the installer device_id = 1 +# Scale down the video feed to this maximum height +# Speeds up face recognition but can make it less precise +max_height = 320 + [debug] # Show a short but detailed diagnostic report in console end_report = false diff --git a/installer.py b/installer.py index 7759d71..fc876a2 100644 --- a/installer.py +++ b/installer.py @@ -80,7 +80,7 @@ handleStatus(subprocess.call(["rm", "-rf", "/tmp/dlib_clone"])) log("Installing face_recognition") -handleStatus(subprocess.call(["pip3", "install", "face_recognition"])) +handleStatus(subprocess.call(["pip3", "install", "face_recognition", "sty"])) log("Cloning howdy")