From ad2bfd50c5a07ff61fad46cbe29f654eafec63cf Mon Sep 17 00:00:00 2001 From: boltgolt Date: Thu, 3 May 2018 15:47:44 +0200 Subject: [PATCH 1/6] Added fixes for #29 and #30 --- debian/changelog | 6 ++++++ src/compare.py | 15 ++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/debian/changelog b/debian/changelog index ca45c855..2006bf19 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +howdy (2.2.1) xenial; urgency=medium + + * Add notes + + -- boltgolt Thu, 03 May 2018 13:23:09 +0200 + howdy (2.1.0) xenial; urgency=medium * First complete PPA release diff --git a/src/compare.py b/src/compare.py index db1dde9f..3a5ff023 100644 --- a/src/compare.py +++ b/src/compare.py @@ -37,8 +37,6 @@ def stop(status): models = [] # Encoded face models encodings = [] -# Amount of frames already matched -tries = 0 # Amount of ingnored dark frames dark_tries = 0 @@ -82,6 +80,10 @@ def stop(status): # Increment the frame count every loop frames += 1 + # Stop if we've exceded the time limit + if time.time() - timings[3] > int(config.get("video", "timout")): + stop(11) + # Grab a single frame of video # Don't remove ret, it doesn't work without it ret, frame = video_capture.read() @@ -109,9 +111,6 @@ def stop(status): # Save the new size for diagnostics 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) @@ -158,9 +157,3 @@ def print_timing(label, offset): # End peacegully stop(0) - - # Stop if we've exceded the maximum retry count - if time.time() - timings[3] > int(config.get("video", "timout")): - stop(11) - - tries += 1 From 2002f4c6b59da0bfea770c59d83cca9ef28dcad3 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Thu, 3 May 2018 16:12:17 +0200 Subject: [PATCH 2/6] More fixes for #27 --- src/cli/add.py | 6 ++++++ src/cli/test.py | 4 ++++ src/compare.py | 4 ++++ src/config.ini | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/src/cli/add.py b/src/cli/add.py index c9f05941..374ee743 100644 --- a/src/cli/add.py +++ b/src/cli/add.py @@ -80,6 +80,12 @@ # Open the camera video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) + +# Force MJPEG decoding if true +if config.get("debug", "force_mjpeg") == "true": + video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237) + +# Request a frame to wake the camera up video_capture.read() print("\nPlease look straight into the camera") diff --git a/src/cli/test.py b/src/cli/test.py index 191ce666..ba4b979f 100644 --- a/src/cli/test.py +++ b/src/cli/test.py @@ -20,6 +20,10 @@ # Start capturing from the configured webcam video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) +# Force MJPEG decoding if true +if config.get("debug", "force_mjpeg") == "true": + video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237) + # Let the user know what's up print(""" Opening a window with a test feed diff --git a/src/compare.py b/src/compare.py index 3a5ff023..b25e80a5 100644 --- a/src/compare.py +++ b/src/compare.py @@ -60,6 +60,10 @@ def stop(status): # Start video capture on the IR camera video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) +# Force MJPEG decoding if true +if config.get("debug", "force_mjpeg") == "true": + video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237) + # Capture a single frame so the camera becomes active # This will let the camera adjust its light levels while we're importing for faster scanning video_capture.read() diff --git a/src/config.ini b/src/config.ini index 213890f1..146f1e87 100644 --- a/src/config.ini +++ b/src/config.ini @@ -33,6 +33,10 @@ device_id = 1 # Speeds up face recognition but can make it less precise max_height = 320 +# Force the use of Motion JPEG when decoding frames, fixes issues with +# YUYV raw frame deconding +force_mjpeg = false + # Because of flashing IR emitters, some frames can be completely unlit # Skip the frame if the lowest 1/8 of the histogram is above this percentage # of the total From b9866d7e900b5ac3b7513b1fd404a8df04260323 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Fri, 4 May 2018 14:24:26 +0200 Subject: [PATCH 3/6] Updating badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c219979c..9f3a4061 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Howdy for Ubuntu [![](https://img.shields.io/travis/Boltgolt/howdy/master.svg)](https://travis-ci.org/Boltgolt/howdy) [![](https://img.shields.io/github/release/Boltgolt/howdy.svg?colorB=4c1)](https://github.com/Boltgolt/howdy/releases) ![](https://boltgolt.nl/howdy_badge/installs.php) +# Howdy for Ubuntu [![](https://img.shields.io/travis/Boltgolt/howdy/master.svg)](https://travis-ci.org/Boltgolt/howdy) [![](https://img.shields.io/github/release/Boltgolt/howdy.svg?colorB=4c1)](https://github.com/Boltgolt/howdy/releases) ![](https://boltgolt.nl/howdy_badge/installs.php?nc) ![](https://boltgolt.nl/howdy_badge/views.php) Windows Helloâ„¢ style authentication for Ubuntu. Use your built-in IR emitters and camera in combination with face recognition to prove who you are. From 5ac5070d11b8cffdb363b22c54508c481e249e8c Mon Sep 17 00:00:00 2001 From: boltgolt Date: Fri, 4 May 2018 21:39:52 +0200 Subject: [PATCH 4/6] Updated the autocomplete file and disable command --- autocomplete/howdy | 33 +++++++++++++++++++++++++++++++-- src/cli/disable.py | 11 ++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/autocomplete/howdy b/autocomplete/howdy index 40ce2a23..339bccac 100755 --- a/autocomplete/howdy +++ b/autocomplete/howdy @@ -5,11 +5,40 @@ _howdy() { local cur prev opts COMPREPLY=() + # The argument typed so far cur="${COMP_WORDS[COMP_CWORD]}" + # The previous argument prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="help list add remove clear" - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + # Go though all cases we support + case "${prev}" in + # After the main command, show the commands + "howdy") + opts="add clear config disable list remove clear test" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; + # For disable, grab the current "disabled" config option and give the reverse + "disable") + local status=$(cut -d'=' -f2 <<< $(cat /lib/security/howdy/config.ini | grep 'disabled =') | xargs echo -n) + + [ "$status" == "false" ] && COMPREPLY="true" || COMPREPLY="false" + return 0 + ;; + # List the users availible + "-U") + COMPREPLY=( $(compgen -u -- ${cur}) ) + return 0 + ;; + "--user") + COMPREPLY=( $(compgen -u -- ${cur}) ) + return 0 + ;; + *) + ;; + esac + + # Nothing matched, so return nothing return 0 } diff --git a/src/cli/disable.py b/src/cli/disable.py index 2c2b03b6..8bc03416 100644 --- a/src/cli/disable.py +++ b/src/cli/disable.py @@ -21,13 +21,18 @@ sys.exit(1) # Translate the argument to the right string -if builtins.howdy_args.argument == "1": +if builtins.howdy_args.argument == "1" or builtins.howdy_args.argument.lower() == "true": out_value = "true" -elif builtins.howdy_args.argument == "0": +elif builtins.howdy_args.argument == "0" or builtins.howdy_args.argument.lower() == "false": out_value = "false" else: # Of it's not a 0 or a 1, it's invalid - print("Please only use a 0 (enable) or a 1 (disable) as an argument") + print("Please only use false (enable) or true (disable) as an argument") + sys.exit(1) + +# Don't do anything when the state is already the requested one +if out_value == config.get("core", "disabled"): + print("The disable option has already been set to " + out_value) sys.exit(1) # Loop though the config file and only replace the line containing the disable config From 22cc108e870b0ed2ced7bb53e17515658200ec5f Mon Sep 17 00:00:00 2001 From: boltgolt Date: Thu, 10 May 2018 15:05:27 +0200 Subject: [PATCH 5/6] Added auto config backup and restore for upgarades This does remove all comments from the config file --- autocomplete/howdy | 1 + debian/postinst | 30 ++++++++++++++++++++++++++++-- debian/preinst | 14 ++++++++++++++ src/compare.py | 2 +- src/config.ini | 2 ++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/autocomplete/howdy b/autocomplete/howdy index 339bccac..e3bde07d 100755 --- a/autocomplete/howdy +++ b/autocomplete/howdy @@ -42,4 +42,5 @@ _howdy() { return 0 } +# Register the autocomplete function complete -F _howdy howdy diff --git a/debian/postinst b/debian/postinst index efe76a18..5c40df6b 100755 --- a/debian/postinst +++ b/debian/postinst @@ -36,8 +36,34 @@ def handleStatus(status): sys.exit(1) -# We're not in fresh configuration mode (probably an upgrade), so exit +# We're not in fresh configuration mode so don't continue the setup if not os.path.exists("/tmp/howdy_picked_device"): + # Check if we have an older config we can restore + if len(sys.argv) > 2: + if os.path.exists("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"): + # Get the config parser + import configparser + + # Load th old and new config files + oldConf = configparser.ConfigParser() + oldConf.read("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") + newConf = configparser.ConfigParser() + newConf.read("/lib/security/howdy/config.ini") + + # Go through every setting in the old config and apply it to the new file + for section in oldConf.sections(): + for (key, value) in oldConf.items(section): + try: + newConf.set(section, key, value) + # Add a new section where needed + except configparser.NoSectionError as e: + newConf.add_section(section) + newConf.set(section, key, value) + + # Write it all to file + with open("/lib/security/howdy/config.ini", "w") as configfile: + newConf.write(configfile) + sys.exit(0) # Open the temporary file containing the device ID @@ -162,7 +188,7 @@ if "HOWDY_NO_PROMPT" not in os.environ: # Abort the whole thing if it's not if (ans.lower() != "y"): - print("Inerpeting as a \"NO\", aborting") + print("Interpreting as a \"NO\", aborting") sys.exit(1) print("Adding lines to PAM\n") diff --git a/debian/preinst b/debian/preinst index 02960a8d..33572beb 100755 --- a/debian/preinst +++ b/debian/preinst @@ -16,6 +16,20 @@ import os import re import signal +# Backup the config file if we're upgrading +if "upgrade" in sys.argv: + # Try to copy the config file as a backup + try: + subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + + # Let the user know so he knows where to look on a failed install + print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") + except e: + print("Could not make an backup of old Howdy config file") + + # Don't continue setup when we're just upgrading + sys.exit(0) + # Don't run if we're not trying to install fresh if "install" not in sys.argv: sys.exit(0) diff --git a/src/compare.py b/src/compare.py index b25e80a5..a1a08697 100644 --- a/src/compare.py +++ b/src/compare.py @@ -61,7 +61,7 @@ def stop(status): video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) # Force MJPEG decoding if true -if config.get("debug", "force_mjpeg") == "true": +if config.get("video", "force_mjpeg") == "true": video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237) # Capture a single frame so the camera becomes active diff --git a/src/config.ini b/src/config.ini index 146f1e87..ac5e06dd 100644 --- a/src/config.ini +++ b/src/config.ini @@ -46,3 +46,5 @@ dark_threshold = 50 [debug] # Show a short but detailed diagnostic report in console end_report = false + +dummy = true From d7242688a63e7d25cb51db60b08bb5d78f3e9a77 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Thu, 10 May 2018 15:20:29 +0200 Subject: [PATCH 6/6] Bumping changelog and travis fix --- .travis.yml | 4 ++++ debian/changelog | 8 ++++++-- debian/control | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bbd8344a..24f64115 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,7 @@ notifications: email: on_success: never on_failure: always + +addons: + apt: + update: true diff --git a/debian/changelog b/debian/changelog index 2006bf19..f69f3af0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,12 @@ howdy (2.2.1) xenial; urgency=medium - * Add notes + * Added mechanism to keep config files between updates + * Added force_mjpeg option to fix YUYV image issues (thanks @arifeinberg!) + * Revamped the bash autocompletion script + * Fixed timeout never being reached in certain scenarios (thanks @Tkopic001!) + * Fixed issue where BGR to RGB frame conversion caused a crash (thanks @Jerezano!) - -- boltgolt Thu, 03 May 2018 13:23:09 +0200 + -- boltgolt Thu, 10 May 2018 15:14:03 +0200 howdy (2.1.0) xenial; urgency=medium diff --git a/debian/control b/debian/control index 66683112..87f91239 100644 --- a/debian/control +++ b/debian/control @@ -10,6 +10,6 @@ Package: howdy Homepage: https://github.com/Boltgolt/howdy Architecture: all Depends: ${misc:Depends}, git, python3, python3-pip, python3-dev, python3-setuptools, build-essential, libpam-python, fswebcam, libopencv-dev, python-opencv, cmake -Description: Windows Hello style authentication for Ubuntu. +Description: Howdy: Windows Hello style authentication for Ubuntu. Use your built-in IR emitters and camera in combination with face recognition to prove who you are.