-
Notifications
You must be signed in to change notification settings - Fork 2
/
interface.py
111 lines (91 loc) · 2.15 KB
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
import mraa
import pyupm_i2clcd as lcd
import time
import random
import recognizer
import training_interface
from Servo import *
def find_face():
print("TODO: Entering authenticate() stub")
myLCD.clear()
myLCD.setColor(255, 255, 0)
myLCD.setCursor(0, 0)
myLCD.write("Taking picture...")
time.sleep(2)
img = recognizer.take_picture()
myLCD.clear()
myLCD.setCursor(0,0)
myLCD.write("Searching for")
myLCD.setCursor(1,0)
myLCD.write("faces...")
images = recognizer.check_for_face(img)
numfaces = len(images)
print numfaces
if numfaces == 0:
myLCD.clear()
myLCD.setColor(255, 0, 0)
myLCD.setCursor(0,0)
myLCD.write("Face not detected")
time.sleep(2)
return None
else:
return images
def authenticate():
images = find_face()
if images:
for image in images:
recognizer.save_picture("access_request_images","accessimage.png", image)
recognized = recognizer.recognize_face(images)
print recognized
if type(recognized) is str:
denied()
else:
granted()
def granted():
print("TODO: Entering granted() stub")
myLCD.clear()
myLCD.setColor(0, 255, 0)
myLCD.setCursor(0, 0)
myLCD.write("Welcome home,")
myLCD.setCursor(1, 0)
name = random.choice(["Stefan", "Demetra", "Gabrielle"])
myLCD.write(name)
servo.write(170)
time.sleep(5)
servo.write(0)
def denied():
print("TODO: Entering denied() stub")
myLCD.clear()
myLCD.setColor(255, 0, 0)
myLCD.setCursor(0, 0)
myLCD.write("Unauthorized")
myLCD.setCursor(1, 0)
myLCD.write("Calling 911")
time.sleep(5)
def greeting():
myLCD.clear()
myLCD.setColor(255, 255, 255)
myLCD.setCursor(0, 0)
myLCD.write("FaceLock")
myLCD.setCursor(1, 0)
myLCD.write("Press button")
servo.write(0)
BUTTON_PIN = 2
TRAINING_BUTTON_PIN = 8
button = mraa.Gpio(BUTTON_PIN)
training_button = mraa.Gpio(TRAINING_BUTTON_PIN)
button.dir(mraa.DIR_IN)
training_button.dir(mraa.DIR_IN)
## The LCD can only display 16 characters per line
myLCD = lcd.Jhd1313m1(0, 0x3E, 0x62)
servo = Servo("Lock")
servo.attach(3)
greeting()
while True:
if button.read():
authenticate()
if training_button.read():
training_interface.begin_training()
greeting()
time.sleep(0.1)