43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import requests
|
|
import subprocess
|
|
import rsid_py
|
|
import os
|
|
from gpiozero import Button, LED
|
|
from time import sleep
|
|
from signal import pause
|
|
|
|
button = Button("15")
|
|
ledRed = LED("14")
|
|
ledGreen = LED("18")
|
|
|
|
PORT='/dev/ttyACM0'
|
|
|
|
def on_result(result, user_id):
|
|
print('on_result', result)
|
|
if result == rsid_py.AuthenticateStatus.Success:
|
|
takePhoto("success")
|
|
sleep(1.5)
|
|
ledGreen.on()
|
|
sleep(2)
|
|
ledGreen.off()
|
|
else:
|
|
takePhoto("failure")
|
|
sleep(1.5)
|
|
ledRed.on()
|
|
sleep(2)
|
|
ledRed.off()
|
|
|
|
def authentication():
|
|
with rsid_py.FaceAuthenticator(PORT) as f:
|
|
f.authenticate(on_result=on_result)
|
|
|
|
def takePhoto(result):
|
|
filename = subprocess.check_output("date +%Y-%m-%d_%H-%M-%S", shell=True).decode().strip() + "-" + result + ".jpg"
|
|
subprocess.run(["ffmpeg", "-f", "video4linux2", "-i", "/dev/video0", "-vframes", "1", filename])
|
|
os.rename(filename, os.path.join("pictures", filename))
|
|
subprocess.run(["rsync", "-avz", "-e", "ssh", "pictures/", "valer@10.8.0.1:/var/www/valerjakubco.xyz/storage/app/public/pictures/"])
|
|
|
|
|
|
button.when_pressed = authentication
|
|
pause()
|