-
Notifications
You must be signed in to change notification settings - Fork 2
/
system.py
275 lines (157 loc) · 6.31 KB
/
system.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
from classes.employee import Employee
from classes.student import Student
from classes.visitor import Visitor
import pyttsx3
engine = pyttsx3.init()
import face_recognition
import cv2
import numpy as np
import io
known_image_paths = []
known_names = []
def facedetect():
cap = cv2.VideoCapture(0)
_,feed = cap.read()
cv2.imshow("frame",feed)
cv2.waitKey(3000)
ret, frame = cap.read()
if not ret:
print("Failed to capture frame")
exit()
frame_jpg = cv2.imencode('.jpg', frame)[1].tobytes()
cap.release()
cv2.destroyAllWindows()
known_face_encodings = []
for image_path in known_image_paths:
image = face_recognition.load_image_file(image_path)
face_encoding = face_recognition.face_encodings(image)[0]
known_face_encodings.append(face_encoding)
name = image_path.split('/')[-1].split('.')[0]
known_names.append(name)
unknown_image = face_recognition.load_image_file(io.BytesIO(frame_jpg))
face_locations = face_recognition.face_locations(unknown_image)
face_encodings = face_recognition.face_encodings(unknown_image, face_locations)
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
if True in matches:
first_match_index = matches.index(True)
name = known_names[first_match_index]
return name
import speech_recognition as sr
r = sr.Recognizer()
m = sr.Microphone()
def textfromspeech():
with m as source: r.adjust_for_ambient_noise(source)
print("Say something!")
with m as source: audio = r.listen(source,timeout = 5)
value = r.recognize_google(audio)
return value
students = [Student() for _ in range(1000)]
employees = [Employee() for _ in range(1000)]
visitors = [Visitor() for _ in range(1000)]
user_type = ""
user_index = 0
def new_student(name_of_student):
students.append(name_of_student)
known_image_paths.append('faces/' + name_of_student.name + '1.jpeg')
known_image_paths.append('faces/' + name_of_student.name + '2.jpeg')
known_names.append(name_of_student.name)
known_names.append(name_of_student.name)
def new_employee(name_of_employee):
employees.append(name_of_employee)
known_image_paths.append('faces/' + name_of_employee.name + '1.jpeg')
known_image_paths.append('faces/' + name_of_employee.name + '2.jpeg')
known_names.append(name_of_employee.name)
known_names.append(name_of_employee.name)
def new_visitor(name_of_visitor):
visitors.append(name_of_visitor)
known_image_paths.append('faces/' + name_of_visitor.name + '1.jpeg')
known_image_paths.append('faces/' + name_of_visitor.name + '2.jpeg')
known_names.append(name_of_visitor.name)
known_names.append(name_of_visitor.name)
def object_type(input):
global user_type, user_index
for i, student in enumerate(students):
if student.name == input:
user_type = "student"
user_index = i
break
for i, visitor in enumerate(visitors):
if visitor.name == input:
user_type = "visitor"
user_index = i
break
for i, employee in enumerate(employees):
if employee.name == input:
user_type = "employee"
user_index = i
break
dhruv = Student()
dhruv.set_student("dhruv",True)
new_student(dhruv)
hardick = Employee()
hardick.set_employee("hardick",False)
new_employee(hardick)
ayushmaan = Employee()
ayushmaan.set_employee("ayushmaan",False)
new_employee(ayushmaan)
anubhav = Visitor()
anubhav.set_visitor("anubhav",False)
new_visitor(anubhav)
rohit = Student()
rohit.set_student("rohit",True)
new_student(rohit)
nandini= Student()
nandini.set_student("nandini",True)
new_student(nandini)
def main():
input_name = facedetect()
# input_name = input()
object_type(input_name)
print(input_name)
if user_type == "student" and students[user_index].name == input_name and students[user_index].inside_status == True:
engine.say("student recognized successfully")
engine.runAndWait()
engine.say("where do you wish to go")
engine.runAndWait()
destination = textfromspeech()
students[user_index].visit_place = destination
students[user_index].inside_status = False
engine.say("Enjoy your visit to ")
engine.say(str(destination))
engine.runAndWait()
elif user_type == "student" and students[user_index].name == input_name and students[user_index].inside_status == False:
engine.say("student recognized successfully")
engine.runAndWait()
engine.say("welcome back to the campus")
engine.runAndWait()
students[user_index].visit_place = "campus"
students[user_index].inside_status = True
elif user_type == "employee" and employees[user_index].name == input_name and employees[user_index].inside_status == True:
engine.say("employee recognized successfully")
engine.runAndWait()
engine.say("happy journey")
engine.runAndWait()
employees[user_index].inside_status = False
elif user_type == "employee" and employees[user_index].name == input_name and employees[user_index].inside_status == False:
engine.say("employee recognized successfully")
engine.runAndWait()
engine.say("welcome back to the campus")
engine.runAndWait()
employees[user_index].inside_status = True
elif user_type == "visitor" and visitors[user_index].name == input_name and visitors[user_index].inside_status == True:
engine.say("visitor recognized successfully")
engine.runAndWait()
engine.say("please come again")
engine.runAndWait()
visitors[user_index].inside_status == False
elif user_type == "visitor" and visitors[user_index].name == input_name and visitors[user_index].inside_status == False:
engine.say("visitor recognized successfully")
engine.runAndWait()
engine.say("You must leave the campus within 4 hours from now")
engine.runAndWait()
visitors[user_index].inside_status == True
main()
if __name__ == "__main__":
main()