From a0166ccae344b013354b8e3f14b294f6aded770b Mon Sep 17 00:00:00 2001 From: Matan Arnon Date: Wed, 5 Jan 2022 18:01:18 +0200 Subject: [PATCH] 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