-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
''' | ||
Communicate with AWS | ||
''' | ||
|
||
import boto3 | ||
|
||
''' | ||
Call AWS | ||
''' | ||
def main(bucket, key, bucket_target, key_target, threshold=80, region="us-east-1"): | ||
rekognition = boto3.client("rekognition", region) | ||
response = rekognition.compare_faces( | ||
SourceImage={ | ||
"S3Object": { | ||
"Bucket": bucket, | ||
"Name": key, | ||
} | ||
}, | ||
TargetImage={ | ||
"S3Object": { | ||
"Bucket": bucket_target, | ||
"Name": key_target, | ||
} | ||
}, | ||
SimilarityThreshold=threshold, | ||
) | ||
|
||
# Check for similarity string | ||
try: | ||
#print(response) | ||
compare = response['FaceMatches'][0]['Similarity'] | ||
except: | ||
compare = "0" | ||
return response['SourceImageFace'], response['FaceMatches'], compare | ||
|
||
if __name__== "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sat Feb 2 15:28:12 2019 | ||
@author: maksim | ||
Libraries used | ||
pip install boto3 | ||
pip install awscli | ||
which aws | ||
aws configure | ||
Disoplay AWS info: cat ~/.aws/credentials | ||
driver | ||
take_pic | ||
post_pic | ||
Driver script, communicates with AWS | ||
""" | ||
import take_pic | ||
import post_pic | ||
import compare_faces | ||
from servo import lock, unlock | ||
|
||
BUCKET = "securitycamera1" # Bucket name | ||
KEY_SOURCE = "new_image.jpg" # New Image | ||
KEY_TARGET = "saved_image.jpg" # Person's Image | ||
|
||
|
||
''' | ||
The main function | ||
''' | ||
|
||
|
||
def main(): | ||
# Take the picture | ||
take_pic.main(KEY_SOURCE) | ||
|
||
# Send the picture to AWS | ||
post_pic.main(BUCKET, KEY_SOURCE) | ||
|
||
# Flag variable | ||
flag = True | ||
information = {} | ||
|
||
# Get the similarity | ||
try: | ||
source_face, matches, similarity = compare_faces.main(BUCKET, KEY_SOURCE, BUCKET, KEY_TARGET) | ||
except: | ||
flag = False | ||
information["status"] = "not_auth" | ||
|
||
if(flag): | ||
try: | ||
# if it is 80% | ||
if(int(similarity) > 80): | ||
flag = True | ||
print ("Face maches: " + str(similarity)) | ||
# If the face doesn't match or the accuracy is very low | ||
else: | ||
flag = False | ||
information["status"] = "not_auth" | ||
print("Face doesn't match!") | ||
except: | ||
flag = False | ||
information["status"] = "not_auth" | ||
|
||
print("flag: " + str(flag)) | ||
|
||
if flag: | ||
unlock() | ||
information["status"] = "unlocked" | ||
|
||
else: | ||
lock() | ||
information["status"] = "locked" | ||
|
||
return information | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import serial | ||
from time import sleep | ||
|
||
ser = serial.Serial('/dev/ttyACM0', 9600) | ||
status = {"locked": '1', "unlocked": '2', "take_pic": '3', "not_auth": '4'} | ||
|
||
|
||
def write_lcd(current_stat): | ||
try: | ||
|
||
ser.write(status[current_stat].encode()) | ||
print("yes") | ||
|
||
except KeyboardInterrupt as e: | ||
exit() | ||
|
||
except Exception as e: | ||
print("error: {}".format(e)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
import RPi.GPIO as GPIO | ||
from driver import main | ||
from time import sleep | ||
from lcd_controller import write_lcd | ||
|
||
TouchPin = 15 | ||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setup(TouchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||
|
||
touched = False | ||
|
||
|
||
def loop(): | ||
|
||
global touched | ||
while True: | ||
if GPIO.input(TouchPin) == GPIO.LOW: | ||
touched = False | ||
else: | ||
print("Touched") | ||
write_lcd("take_pic") | ||
touched = True | ||
result = main() | ||
write_lcd(result["status"]) | ||
sleep(2) | ||
|
||
|
||
def destroy(): | ||
GPIO.cleanup() # Release resource | ||
|
||
|
||
if __name__ == '__main__': # Program start from here | ||
try: | ||
loop() | ||
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. | ||
destroy() |