mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-12 09:41:18 +02:00
Added proof of concept
This commit is contained in:
parent
4452c04fd0
commit
4b3f3064ce
4 changed files with 103 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -99,3 +99,6 @@ ENV/
|
|||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# Ignore generated models
|
||||
/models
|
||||
|
|
53
compair.py
Normal file
53
compair.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
import face_recognition
|
||||
import cv2
|
||||
import sys
|
||||
import os
|
||||
|
||||
def stop(status):
|
||||
video_capture.release()
|
||||
sys.exit(status)
|
||||
|
||||
path = ""
|
||||
distance = 3
|
||||
|
||||
try:
|
||||
if not isinstance(sys.argv[1], str):
|
||||
sys.exit(1)
|
||||
except IndexError:
|
||||
sys.exit(1)
|
||||
|
||||
user = sys.argv[1]
|
||||
|
||||
# Get a reference to webcam #0 (the default one)
|
||||
video_capture = cv2.VideoCapture(1)
|
||||
|
||||
encodings = []
|
||||
|
||||
try:
|
||||
for exposure in ["L", "M", "S"]:
|
||||
ref = face_recognition.load_image_file(path + "/" + user + "/" + exposure + ".jpg")
|
||||
enc = face_recognition.face_encodings(ref)[0]
|
||||
encodings.append(enc)
|
||||
except FileNotFoundError:
|
||||
stop(802)
|
||||
|
||||
tries = 0
|
||||
|
||||
while True:
|
||||
# Grab a single frame of video
|
||||
ret, frame = video_capture.read()
|
||||
|
||||
face_encodings = face_recognition.face_encodings(frame)
|
||||
|
||||
# Loop through each face in this frame of video
|
||||
for face_encoding in face_encodings:
|
||||
matches = face_recognition.face_distance(encodings, face_encoding)
|
||||
|
||||
for match in matches:
|
||||
if match < distance:
|
||||
stop(0)
|
||||
|
||||
if tries => 100:
|
||||
stop(801)
|
||||
|
||||
tries += 1
|
29
learn.py
Normal file
29
learn.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import subprocess
|
||||
import time
|
||||
import os
|
||||
|
||||
user = os.environ.get("USER")
|
||||
|
||||
if not os.path.exists("models"):
|
||||
os.makedirs("models")
|
||||
|
||||
if not os.path.exists("models/" + user):
|
||||
print("No face model folder found, creating one")
|
||||
os.makedirs("models/" + user)
|
||||
|
||||
print("Learning face for the user account " + os.environ.get("USER"))
|
||||
print("Please look straigt into the camera for 5 seconds")
|
||||
|
||||
time.sleep(2.5)
|
||||
|
||||
subprocess.call(["fswebcam", "-S", "30", "--no-banner", "-d", "/dev/video1", "./models/" + user + "/L.jpg"], stderr=open(os.devnull, "wb"))
|
||||
|
||||
time.sleep(.3)
|
||||
|
||||
subprocess.call(["fswebcam", "-S", "6", "--no-banner", "-d", "/dev/video1", "./models/" + user + "/M.jpg"], stderr=open(os.devnull, "wb"))
|
||||
|
||||
time.sleep(.3)
|
||||
|
||||
subprocess.call(["fswebcam", "--no-banner", "-d", "/dev/video1", "./models/" + user + "/S.jpg"], stderr=open(os.devnull, "wb"))
|
||||
|
||||
print("Done.")
|
18
pam.py
Normal file
18
pam.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
def pam_sm_authenticate(pamh, flags, args):
|
||||
status = subprocess.call(["python3", "compair.py", pamh.get_user()])
|
||||
|
||||
if status == 801:
|
||||
print("Timeout reached, ould not find a known face")
|
||||
return pamh.PAM_SYSTEM_ERR
|
||||
if status == 34:
|
||||
print("No face model is known for this user")
|
||||
return pamh.PAM_SYSTEM_ERR
|
||||
if status == 0:
|
||||
print("Identified face as " + os.environ.get("USER"))
|
||||
return pamh.PAM_SUCCESS
|
||||
|
||||
return pamh.PAM_SYSTEM_ERR
|
Loading…
Reference in a new issue