-
Notifications
You must be signed in to change notification settings - Fork 0
/
recognition_sms.py
225 lines (202 loc) · 6.87 KB
/
recognition_sms.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import cv2
import numpy as np
import pygame
import time
import socket
from thread import start_new_thread
from twilio.rest import TwilioRestClient
print 'started'
model=cv2.createLBPHFaceRecognizer(radius=1,neighbors=9,grid_x=8,grid_y=8,threshold=60)
model.load("./trainer.xml")
print "loaded"
pygame.init()
disp=pygame.display.set_mode((640,480))
disp.fill((0,0,255))
#set font for displaying the information
font=pygame.font.SysFont('Calibri',76,True,False)
recog=False
server_answered=False
def connect_server():
global server_answered,recog
try:
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("localhost",7567))
s.sendall("start_recog")
ans=s.recv(1024)
if(ans == "authorized"):
server_answered = True
recog = True
else:
server_answered = True
recog = False
except:
server_answered=True
recog=False
def server_connect():
global server_answered,recog
server_answered=False
print "do your code here"
running=True
start_new_thread(connect_server,())
while(running):
disp.fill((0,0,0))
for(events) in pygame.event.get():
pass
if(server_answered):
time.sleep(0.1)
running=False
if(recog):
return True
else:
return False
pygame.tick(10)
def pin_entry(tries=0):
dispx=640
dispy=480
chkPass="4519"
running=True
dispy=float(dispy)*4/5;
numbers=[[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
numbers_string=[['1','2','3'],['4','5','6'],['7','8','9'],['Clear','0','Enter']]
for i in range(4):
for j in range(3):
numbers[i][j]=pygame.Rect(j*dispx/3+10,(i+1)*dispy/4+20,dispx/3-20,dispy/4-40)
def draw_again():
global disp
num=0
disp.fill((0, 0, 0))
for i in range(4):
for j in range(3):
pygame.draw.rect(disp, (100, 140, 170), numbers[i][j])
if (num < 9):
num += 1
label = font.render(str(num), 1, (255, 255, 255))
disp.blit(label, (j * dispx / 3 +84, ((i + 1) * dispy / 4)+15 ))
pygame.draw.rect(disp, (255, 0, 0), numbers[3][0])
pygame.draw.rect(disp, (255, 0, 0), numbers[3][2])
label = font.render("Clear", 1, (255, 255, 255))
disp.blit(label, (0 * dispx / 3+23 , ((3 + 1) * dispy / 4) + 15))
label = font.render(str(0), 1, (255, 255, 255))
disp.blit(label, (1 * dispx / 3 + 84, ((3 + 1) * dispy / 4) + 15))
label = font.render("Enter", 1, (255, 255, 255))
disp.blit(label, (2 * dispx / 3 +23, ((3 + 1) * dispy / 4) + 15))
numbers[3][1]=pygame.Rect(1*dispx/3+10,(3+1)*dispy/4+20,dispx/3-20,dispy/4-40)
disp_pass=''
passw=""
draw_again()
while(running):
mousex, mousey=0,0
for events in pygame.event.get():
if(events.type==pygame.QUIT):
pygame.quit()
if(events.type==pygame.MOUSEBUTTONDOWN):
print passw
mousex,mousey=pygame.mouse.get_pos()
for i in range(4):
for j in range(3):
if numbers[i][j].collidepoint(mousex,mousey):
temp=numbers_string[i][j]
if temp=="Clear":
passw=passw[0:-1]
disp_pass=disp_pass[0:-1]
print disp_pass
draw_again()
elif temp=="Enter":
if(passw==chkPass):
return True
else:
tries+=1
if(tries<3):
disp.fill((0,0,0))
new_pin=pin_entry(tries)
if(new_pin):
return True
return False
else:
disp_pass+='*'
passw+=temp
password=font.render(disp_pass,True,(255,255,255))
disp.blit(password,(0,0))
pygame.display.update()
def send_sms():
acc="Afdsdfs4ff8ddjfg999affgjrm4tjrsfhi"
token="afei45454kljhhhalfu48lafj890adjf"
client=TwilioRestClient(acc,token)
message=client.messages.create(to="+91-xxxxxxxxxx",from_="xxxxxxxxxxx",body="Logged In")
print "Message sent!"
touched=False
face=False
mainloop=True
clock=pygame.time.Clock()
deltaTime=float(0)
timeTaken=float(0)
detected=False
show_text=False
unlock_method=0
while(mainloop):
touched=False
disp.fill((0,0,0))
pygame.display.update()
while(not touched):
for events in pygame.event.get():
if events.type==pygame.QUIT:
pygame.quit()
if events.type==pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pressed()[0]:
touched=True
if(touched):
face=server_connect()
clock.tick(1)
if(face):
detected=True
else:
detected=False
disp.fill((0,0,0))
pygame.display.update()
show_text=True
while(show_text):
timeTaken+=deltaTime
print timeTaken,"use pin"
for(events) in pygame.event.get():
pass
string_=font.render("Use pin please!",True,(255,0,255))
pygame.display.update()
disp.blit(string_,(0,0))
pygame.display.update()
if(timeTaken>1):
touched=False
show_text=False
timeTaken=0
deltaTime=float(clock.tick(30))/1000
pin=pin_entry()
clock.tick(30)
if(pin):
detected=True
else:
detected=False
show_text=True
disp.fill((0,0,0))
pygame.display.update()
while(show_text):
timeTaken+=deltaTime
print timeTaken,"the other thing"
for(events) in pygame.event.get():
pass
if(detected):
string_=font.render("Opened!",True,(0,0,255))
disp.blit(string_,(0,0))
pygame.display.update()
else:
string_=font.render("Not Autherized!",True,(255,0,0))
disp.blit(string_,(0,0))
pygame.display.update()
if(timeTaken>7):
touched=False
show_text=False
timeTaken=0
if(not detected):
disp.fill((0,0,0))
send_sms()
deltaTime=float(clock.tick(30))/1000
pygame.quit()
cv2.destroyAllWindows()