From fbde12bb13aa2726b9b5ba2ca08a6b5e93cb6ece Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Thu, 30 Dec 2021 21:26:21 +0200 Subject: [PATCH 01/10] Fixed typos --- howdy/src/compare.py | 4 ++-- howdy/src/pam.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/howdy/src/compare.py b/howdy/src/compare.py index da90195..bbfc623 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -96,7 +96,7 @@ def send_to_ui(type, message): pass -# Make sure we were given an username to tast against +# Make sure we were given an username to test against if len(sys.argv) < 2: exit(12) @@ -272,7 +272,7 @@ while True: dark_tries += 1 continue - # If the hight is too high + # If the height is too high if scaling_factor != 1: # Apply that factor to the frame frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) diff --git a/howdy/src/pam.py b/howdy/src/pam.py index 5dd3c5d..5e72f76 100644 --- a/howdy/src/pam.py +++ b/howdy/src/pam.py @@ -17,7 +17,7 @@ config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini") def doAuth(pamh): """Starts authentication in a seperate process""" - # Abort is Howdy is disabled + # Abort if Howdy is disabled if config.getboolean("core", "disabled"): return pamh.PAM_AUTHINFO_UNAVAIL From e4faf1c5bfad5291e608bb189ce9235383f32676 Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Fri, 31 Dec 2021 12:03:23 +0200 Subject: [PATCH 02/10] import xlib.display, use it to determine screen orientation --- howdy/src/compare.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/howdy/src/compare.py b/howdy/src/compare.py index bbfc623..4885156 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -22,6 +22,7 @@ import subprocess import snapshot import numpy as np import _thread as thread +import Xlib.display as display from i18n import _ from recorders.video_capture import VideoCapture @@ -193,6 +194,14 @@ del lock # Fetch the max frame height max_height = config.getfloat("video", "max_height", fallback=0.0) + +# Get screen orientaion +landscape = True +dsp = display.Display() +screen_width = dsp.screen().width_in_pixels +screen_height = dsp.screen().height_in_pixels +if screen_height > screen_width: + landscape = False # Get the height of the image height = video_capture.internal.get(cv2.CAP_PROP_FRAME_HEIGHT) or 1 From 3f20e05da4dc15a7c4b124b30fb3ba46650d4e82 Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Fri, 31 Dec 2021 15:21:17 +0200 Subject: [PATCH 03/10] if orientation is portrait, rotate image 90 degrees before scanning for faces --- .vscode/launch.json | 19 +++++++++++++++++++ howdy/src/compare.py | 23 ++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..98167c3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": [ + "matan" + ], + "sudo": true + } + ] +} \ No newline at end of file diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 4885156..0564a42 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -102,8 +102,8 @@ if len(sys.argv) < 2: exit(12) # Get the absolute path to the current directory -PATH = os.path.abspath(__file__ + "/..") - +#PATH = os.path.abspath(__file__ + "/..") +PATH = "/usr/lib/security/howdy" # The username of the user being authenticated user = sys.argv[1] # The model file contents @@ -202,9 +202,11 @@ screen_width = dsp.screen().width_in_pixels screen_height = dsp.screen().height_in_pixels if screen_height > screen_width: landscape = False -# Get the height of the image -height = video_capture.internal.get(cv2.CAP_PROP_FRAME_HEIGHT) or 1 - +# Get the height of the image (which would be the width if screen is portait oriented) +if landscape: + height = video_capture.internal.get(cv2.CAP_PROP_FRAME_HEIGHT) or 1 +else: + height = video_capture.internal.get(cv2.CAP_PROP_FRAME_WIDTH) or 1 # Calculate the amount the image has to shrink scaling_factor = (max_height / height) or 1 @@ -286,11 +288,18 @@ while True: # Apply that factor to the frame frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) gsframe = cv2.resize(gsframe, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) - + # If orientaion is portrait + # Alternate checking photo rotated clockwise and counter clockwise (since we don't know which side portrait is to) + if not landscape: + if frames % 2 == 0: + frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE) + gsframe = cv2.rotate(gsframe, cv2.ROTATE_90_COUNTERCLOCKWISE) + else: + frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE) + gsframe = cv2.rotate(gsframe, cv2.ROTATE_90_CLOCKWISE) # Get all faces from that frame as encodings # Upsamples 1 time face_locations = face_detector(gsframe, 1) - # Loop through each face for fl in face_locations: if use_cnn: From c8c3090d491b4e127e2b5632fe6955040f9f50cc Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Fri, 31 Dec 2021 15:23:38 +0200 Subject: [PATCH 04/10] reverted PATH to original. it was changed for the testing and was returned in previos commit --- howdy/src/compare.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 0564a42..9acdec5 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -102,8 +102,8 @@ if len(sys.argv) < 2: exit(12) # Get the absolute path to the current directory -#PATH = os.path.abspath(__file__ + "/..") -PATH = "/usr/lib/security/howdy" +PATH = os.path.abspath(__file__ + "/..") + # The username of the user being authenticated user = sys.argv[1] # The model file contents From 74728d7f307b7fac56cdd67c529d322ec4c06d7b Mon Sep 17 00:00:00 2001 From: matan-arnon <96633165+matan-arnon@users.noreply.github.com> Date: Fri, 31 Dec 2021 15:30:31 +0200 Subject: [PATCH 05/10] Delete .vscode directory contained configured launch file for debugging. --- .vscode/launch.json | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 98167c3..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "args": [ - "matan" - ], - "sudo": true - } - ] -} \ No newline at end of file From a190af9f266140de2e0a6c0789c571a148808970 Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Fri, 31 Dec 2021 15:32:51 +0200 Subject: [PATCH 06/10] added vscode files to git ignore --- .gitignore | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index 63ef476..6af4659 100644 --- a/.gitignore +++ b/.gitignore @@ -111,3 +111,17 @@ debian/howdy.substvars debian/files debian/debhelper-build-stamp debian/howdy + +# vscode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix \ No newline at end of file From 1937af51b7b39fae3306dff46d3edb59a9581880 Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Fri, 31 Dec 2021 15:50:17 +0200 Subject: [PATCH 07/10] added python3-xlib (library used to determine orientation) to installed pip packages --- howdy/debian/postinst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/howdy/debian/postinst b/howdy/debian/postinst index 0a31c74..ae72b82 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -118,6 +118,11 @@ log("Upgrading numpy to the latest version") # Update numpy handleStatus(subprocess.call(["pip3", "install", "--upgrade", "numpy"])) +log("Installing xlib") + +# Install xlib +handleStatus(subprocess.call(["pip3", "install", "--upgrade", "python3-xlib"])) + log("Downloading and unpacking data files") # Run the bash script to download and unpack the .dat files needed From 069bd5eed9c520b9679a3403dc8119fa573fcb62 Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Fri, 31 Dec 2021 16:08:39 +0200 Subject: [PATCH 08/10] fixed typos found by sider bot --- howdy/src/compare.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 9acdec5..5ca1c50 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -195,14 +195,14 @@ del lock # Fetch the max frame height max_height = config.getfloat("video", "max_height", fallback=0.0) -# Get screen orientaion +# Get screen orientation landscape = True dsp = display.Display() screen_width = dsp.screen().width_in_pixels screen_height = dsp.screen().height_in_pixels if screen_height > screen_width: landscape = False -# Get the height of the image (which would be the width if screen is portait oriented) +# Get the height of the image (which would be the width if screen is portrait oriented) if landscape: height = video_capture.internal.get(cv2.CAP_PROP_FRAME_HEIGHT) or 1 else: @@ -288,7 +288,7 @@ while True: # Apply that factor to the frame frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) gsframe = cv2.resize(gsframe, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) - # If orientaion is portrait + # If orientation is portrait # Alternate checking photo rotated clockwise and counter clockwise (since we don't know which side portrait is to) if not landscape: if frames % 2 == 0: From a0166ccae344b013354b8e3f14b294f6aded770b Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Wed, 5 Jan 2022 18:01:18 +0200 Subject: [PATCH 09/10] removed xlib dependency and installation. Made rotation before face recognition config based --- .vscode/launch.json | 19 +++++++++++++++++++ howdy/debian/postinst | 5 ----- howdy/src/compare.py | 27 +++++++++++++-------------- howdy/src/config.ini | 6 ++++++ 4 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..98167c3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": [ + "matan" + ], + "sudo": true + } + ] +} \ No newline at end of file diff --git a/howdy/debian/postinst b/howdy/debian/postinst index ae72b82..0a31c74 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -118,11 +118,6 @@ log("Upgrading numpy to the latest version") # Update numpy handleStatus(subprocess.call(["pip3", "install", "--upgrade", "numpy"])) -log("Installing xlib") - -# Install xlib -handleStatus(subprocess.call(["pip3", "install", "--upgrade", "python3-xlib"])) - log("Downloading and unpacking data files") # Run the bash script to download and unpack the .dat files needed diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 5ca1c50..3fd7f35 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -22,7 +22,6 @@ import subprocess import snapshot import numpy as np import _thread as thread -import Xlib.display as display from i18n import _ from recorders.video_capture import VideoCapture @@ -151,6 +150,7 @@ end_report = config.getboolean("debug", "end_report", fallback=False) capture_failed = config.getboolean("snapshots", "capture_failed", fallback=False) capture_successful = config.getboolean("snapshots", "capture_successful", fallback=False) gtk_stdout = config.getboolean("debug", "gtk_stdout", fallback=False) +rotate = config.getint("video", "rotate", fallback=0) # Send the gtk outupt to the terminal if enabled in the config gtk_pipe = sys.stdout if gtk_stdout else subprocess.DEVNULL @@ -195,17 +195,9 @@ del lock # Fetch the max frame height max_height = config.getfloat("video", "max_height", fallback=0.0) -# Get screen orientation -landscape = True -dsp = display.Display() -screen_width = dsp.screen().width_in_pixels -screen_height = dsp.screen().height_in_pixels -if screen_height > screen_width: - landscape = False # Get the height of the image (which would be the width if screen is portrait oriented) -if landscape: - height = video_capture.internal.get(cv2.CAP_PROP_FRAME_HEIGHT) or 1 -else: +height = video_capture.internal.get(cv2.CAP_PROP_FRAME_HEIGHT) or 1 +if rotate == 2: height = video_capture.internal.get(cv2.CAP_PROP_FRAME_WIDTH) or 1 # Calculate the amount the image has to shrink scaling_factor = (max_height / height) or 1 @@ -288,9 +280,16 @@ while True: # Apply that factor to the frame frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) gsframe = cv2.resize(gsframe, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) - # If orientation is portrait - # Alternate checking photo rotated clockwise and counter clockwise (since we don't know which side portrait is to) - if not landscape: + # If camera is configured to rotate = 1, check portrait in addition to landscape + if rotate == 1: + if frames % 3 == 1: + frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE) + gsframe = cv2.rotate(gsframe, cv2.ROTATE_90_COUNTERCLOCKWISE) + if frames % 3 == 2: + frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE) + gsframe = cv2.rotate(gsframe, cv2.ROTATE_90_CLOCKWISE) + # If camera is configured to rotate = 2, check portrait orientation + elif rotate == 2: if frames % 2 == 0: frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE) gsframe = cv2.rotate(gsframe, cv2.ROTATE_90_COUNTERCLOCKWISE) diff --git a/howdy/src/config.ini b/howdy/src/config.ini index d89c5dc..d02de0d 100644 --- a/howdy/src/config.ini +++ b/howdy/src/config.ini @@ -80,6 +80,12 @@ force_mjpeg = false # OPENCV only. exposure = -1 +# Rotate captured frames so faces are upright. +# Check landscape orientation only: rotate = 0 +# Check landscape and portrait orientation: rotate = 1 +# Check portrait orientation only: rotate = 2 +rotate = 0 + [snapshots] # Capture snapshots of failed login attempts and save them to disk with metadata # Snapshots are saved to the "snapshots" folder From 2bf52f7a873bfe5ebcdc2379b9bb7b949164737f Mon Sep 17 00:00:00 2001 From: matan-arnon <96633165+matan-arnon@users.noreply.github.com> Date: Wed, 5 Jan 2022 18:04:04 +0200 Subject: [PATCH 10/10] Delete launch.json --- .vscode/launch.json | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 98167c3..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "args": [ - "matan" - ], - "sudo": true - } - ] -} \ No newline at end of file