-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsystemsql.py
196 lines (116 loc) · 4.51 KB
/
systemsql.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
from classes.student import Student
import pyttsx3
import mysql.connector
connection = mysql.connector.connect(host='localhost',
database='DATA',
user='root',
password = 'Raghav')
cursor = connection.cursor()
query = ("SELECT * FROM STUDENTS ;")
cursor.execute(query)
rows = cursor.fetchall()
students = []
known_image_paths = []
known_names = []
for row in rows:
obj = Student()
obj.set_student(row[0],row[2])
pat = [row[4], row[5] , row[6]]
name = [row[0],row[0],row[0]]
students.append(obj)
known_image_paths.append(pat)
known_names.append(name)
connection.close()
engine = pyttsx3.init()
import face_recognition
import cv2
import numpy as np
import io
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
user_type = ""
user_index = 0
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
def main():
connection = mysql.connector.connect(host='localhost',
database='DATA',
user='root',
password = 'Raghav')
cursor = connection.cursor()
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
query = ("UPDATE STUDENTS SET visiting = %s where name = %s")
cursor.execute(query,(destination,input_name,))
students[user_index].inside_status = False
query = ("UPDATE STUDENTS SET in_status = 0 where name = %s ;")
cursor.execute(query(input_name,))
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()
query = ("UPDATE STUDENTS SET visiting = %s Where name = %s ;")
cursor.execute(query,("campus",input_name,))
students[user_index].inside_status = False
query = ("UPDATE STUDENTS SET in_status = 1 Where name = %s ;")
cursor.execute(query,(input_name,))
students[user_index].visit_place = "campus"
students[user_index].inside_status = True
connection.close()
main()
if __name__ == "_main_":
main()