From 5d6fecbe547f207c658b4c2f5d5daee73f4b43ac Mon Sep 17 00:00:00 2001 From: Jinn Koriech Date: Tue, 6 Apr 2021 13:48:41 +0100 Subject: [PATCH 1/3] Add python-opencv as a dependency for ArchLinux --- archlinux/howdy/.SRCINFO | 1 + 1 file changed, 1 insertion(+) diff --git a/archlinux/howdy/.SRCINFO b/archlinux/howdy/.SRCINFO index cf7022d..0fbef43 100644 --- a/archlinux/howdy/.SRCINFO +++ b/archlinux/howdy/.SRCINFO @@ -13,6 +13,7 @@ pkgbase = howdy depends = python3 depends = python-dlib depends = python-numpy + depends = python-opencv backup = usr/lib/security/howdy/config.ini source = howdy-2.6.1.tar.gz::https://github.com/boltgolt/howdy/archive/v2.6.1.tar.gz source = https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2 From 39272035aff22bfc827e9ab93d1b1b03579ae7d2 Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Sun, 31 Jan 2021 10:58:37 +0100 Subject: [PATCH 2/3] Close test using Close window button --- src/cli/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/test.py b/src/cli/test.py index c62fcef..20a10a1 100644 --- a/src/cli/test.py +++ b/src/cli/test.py @@ -80,7 +80,7 @@ rec_tm = 0 # Wrap everything in an keyboard interupt handler try: - while True: + while cv2.getWindowProperty("Howdy Test", cv2.WND_PROP_VISIBLE) > 0: frame_tm = time.time() # Increment the frames From 108ddd5e9409dd38bd2aeb2e7d16c7d2a9d08d4d Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Sun, 31 Jan 2021 11:00:05 +0100 Subject: [PATCH 3/3] Show model label detected --- src/cli/test.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/cli/test.py b/src/cli/test.py index 20a10a1..bfd12f5 100644 --- a/src/cli/test.py +++ b/src/cli/test.py @@ -2,11 +2,14 @@ # Import required modules import configparser +import builtins import os +import json import sys import time import dlib import cv2 +import numpy as np from recorders.video_capture import VideoCapture # Get the absolute path to the current file @@ -59,6 +62,22 @@ if use_cnn: else: face_detector = dlib.get_frontal_face_detector() +pose_predictor = dlib.shape_predictor(path + "/../dlib-data/shape_predictor_5_face_landmarks.dat") +face_encoder = dlib.face_recognition_model_v1(path + "/../dlib-data/dlib_face_recognition_resnet_model_v1.dat") + +encodings = [] +models = None + +try: + user = builtins.howdy_user + models = json.load(open(path + "/../models/" + user + ".dat")) + + for model in models: + encodings += model["data"] +except FileNotFoundError: + print("No face model known for the user " + user + ", please run:") + print("\n\tsudo howdy -U " + user + " add\n") + clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) # Open the window and attach a a mouse listener @@ -97,7 +116,7 @@ try: sec_frames = 0 # Grab a single frame of video - _, frame = video_capture.read_frame() + orig_frame, frame = video_capture.read_frame() frame = clahe.apply(frame) # Make a frame to put overlays in @@ -155,6 +174,23 @@ try: if use_cnn: loc = loc.rect + color = (0, 0, 230) + if models: + face_landmark = pose_predictor(orig_frame, loc) + face_encoding = np.array(face_encoder.compute_face_descriptor(orig_frame, face_landmark, 1)) + + # Match this found face against a known face + matches = np.linalg.norm(encodings - face_encoding, axis=1) + + # Get best match + match_index = np.argmin(matches) + match = matches[match_index] + + percent = match * 100 + label = models[match_index]["label"] + color = (230, 0, 0) + cv2.putText(overlay, "{} {}(%)".format(label, percent), (width - 68, 32), cv2.FONT_HERSHEY_SIMPLEX, .3, (0, 255, 0), 0, cv2.LINE_AA) + # Get the center X and Y from the rectangular points x = int((loc.right() - loc.left()) / 2) + loc.left() y = int((loc.bottom() - loc.top()) / 2) + loc.top() @@ -165,7 +201,7 @@ try: r = int(r + (r * 0.2)) # Draw the Circle in green - cv2.circle(overlay, (x, y), r, (0, 0, 230), 2) + cv2.circle(overlay, (x, y), r, color, 2) # Add the overlay to the frame with some transparency alpha = 0.65