Skip to content

Commit

Permalink
migrating from gitlab to github for the devpost.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohades committed Feb 3, 2019
1 parent 434307d commit e3c5724
Show file tree
Hide file tree
Showing 28 changed files with 1,012 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/Security Camera.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

499 changes: 499 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 153 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added __pycache__/compare_faces.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/driver.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/image_helpers.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/post_pic.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/post_pic.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/take_pic.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/take_pic.cpython-37.pyc
Binary file not shown.
37 changes: 37 additions & 0 deletions compare_faces.py
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()
Binary file added compare_faces.pyc
Binary file not shown.
84 changes: 84 additions & 0 deletions driver.py
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()
Binary file added driver.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions lcd_controller.py
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))
Binary file added lcd_controller.pyc
Binary file not shown.
37 changes: 37 additions & 0 deletions main.py
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()
Binary file added new_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e3c5724

Please sign in to comment.