-
Notifications
You must be signed in to change notification settings - Fork 3
/
aidooropenmainscript.py
149 lines (121 loc) · 3.29 KB
/
aidooropenmainscript.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
import face_recognition
import pickle
import numpy as np
import cv2
import numpy as np
from PIL import Image,ImageDraw,ImageFont
import pickle
import smtpmail as d
import ledblink as y
import aiservo as z
import aiservo2 as a
import spee as e
m=1
t=None
l=[]
r=[]
b=[]
u=[]
fonts = cv2.FONT_HERSHEY_SIMPLEX
p=0
# org
org = (50, 50)
# fontScale
fontScale = 1
# Blue color in BGR
color = (255, 255, 0)
# Line thickness of 2 px
thickness = 2
# Using cv2.putText() method
# Load face encodings
with open('dataset_papa.dat', 'rb') as f:
all_face_encodings = pickle.load(f)
known_face_names = list(all_face_encodings.keys())
known_face_encodings = np.array(list(all_face_encodings.values()))
n=10;
q=10;
i=0
cap=cv2.VideoCapture(0)
while True:
ret,img=cap.read()
s=[]
i=i+1
print(i)
cv2.imwrite("stijo3.jpg", img)
test_image=face_recognition.load_image_file('stijo3.jpg')
face_locations=face_recognition.face_locations(test_image)
face_encodings = face_recognition.face_encodings(test_image,face_locations)
pil_image=Image.fromarray(test_image)
draw=ImageDraw.Draw(pil_image)
font = ImageFont.truetype("Arial.ttf",10)
# Using cv2.putText() method
for (top,right,bottom,left) ,face_encoding in zip(face_locations,face_encodings):
matches=face_recognition.compare_faces(known_face_encodings,face_encoding)
name="Unknown Person"
if True in matches:
first_match_index=matches.index(True)
name=known_face_names[first_match_index]
draw.rectangle(((left+2,top+2),(right+2,bottom+2)),outline=(255,255,0))
text_width,text_height=draw.textsize(name)
draw.rectangle(((left,bottom-text_height-10),(right,bottom)),fill=(255,255,0),outline=(255,255,0))
draw.text((left+6,bottom-text_height-5),name,fill=(255,255,255,0),font=font)
l.append(left)
r.append(right)
u.append(text_height)
b.append(bottom)
print(name)
s.append(name)
p=p+1
del draw
img = np.array(pil_image)
img= cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# print(s)
for t in s:
print(t)
if t is not None :
for h in range(0,p):
print(t)
img= cv2.putText(img,s[h],(l[h]+6,b[h]-u[h]-5), fonts,
fontScale, color, thickness,cv2.LINE_AA)
cv2.imshow("test",img)
i=i+1
print(i)
t=None
p=0
if i==100:
i=0
cv2.destroyAllWindows()
key=cv2.waitKey(1)
if key ==ord('q') & 0xFF:
break
for o in s:
if o=="stijo":
n=n+1
#print("got")
if n==0 or n>6:
y.ledh()
e.speakout("access ..granted.. door unlocked welcome home")
a.ser()
z.ser()
m=2
n=1
elif o=="Unknown Person"or o=="salimma" or "papa":
q=q+1
if q==0 or q>4:
cv2.imwrite("intruder.jpg", img)
d.mails()
y.ledblink()
e.speakout("access.. denied .. door cannot be opened")
q=1
if (m%2)==0:
m=m+2
if m==10:
m=1
y.ledlow()
z.ser2()
a.ser2()
s.clear()
l.clear()
b.clear()
u.clear()
cv2.destroyAllWindows()