You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtkinterastk#Used to make GUI and fullscreen lock-screen
2
2
importnumpyasnp
3
3
importcv2
4
4
fromPILimportImage, ImageTk
5
-
importface_recognition
6
-
fromUtilsimportBlocking
5
+
importface_recognition#Library Used for Face Recognition
6
+
fromUtilsimportBlocking#To Block Keyboard and Mouse Temporarily
7
7
fromPILimportImageTkasitk
8
-
fromwin32apiimportGetSystemMetrics
9
-
fromgttsimportgTTS
8
+
fromwin32apiimportGetSystemMetrics# To get resolution of monitor
9
+
fromgttsimportgTTS# Text to Speech
10
10
fromioimportBytesIO
11
-
importplaysound
11
+
importplaysound# Play Sound
12
12
importos
13
-
importwinsound
13
+
importwinsound# To play background music
14
14
15
15
bg="Images/bg.jpg"
16
-
bgmusic='Images/bluedanube.wav'
16
+
bgmusic='Images/bluedanube.wav'# These two are default wallpaper and music
17
17
18
+
# Asking User whether they wish to use customization
18
19
customizeOrNot=input("Press \'Y\' or \'y\' if you wish to customize background music and wallpaper \n")
19
20
ifcustomizeOrNot.lower() =='y':
20
21
bg="Images/"+input("Enter filename of wallpaper : ")
21
22
bgmusic="Images/"+input("Enter filename of music file (WAV only) : ")
22
23
23
-
name=input("Please Enter First Name Entered During Registration: ")
24
-
#if name+"png" in
25
-
26
24
25
+
# This name variable is used to get original picture of user generated using faceRegister module
26
+
name=input("Please Enter First Name Entered During Registration: ")
27
27
28
28
length=""
29
29
30
30
31
+
# We are using try and except block to make sure that if user enters wrong Name (One that doesn't exists in faceRegister Folder) program is terminated.
iffaceDis[0]<=0.4:# Here we are checking that if distance is less than 0.4 which can be also understood as whether the confidence level of Image being same is greater than 60 % or not (less distance more confidence)
135
+
flagNoone=0# We are in Correct Image Detected so flag no one is 0
136
+
flagWrong=0# We are in Correct Image Detected so flag wrong one is 0
137
+
winsound.PlaySound(None, winsound.SND_FILENAME)# Don't Play any music (music is only played when no face is detected). We can just play None to mute it.
126
138
#print(faceDis[0])
127
139
#print(faceDis[0]<=0.4)
128
-
final_answer=True
140
+
final_answer=True# If confidence level is greater than 60% faces match and append the result in list
129
141
final_answer_list.append(final_answer)
130
-
counter2=counter2+1
131
-
l2.config(text=f'{counter2} test passed ✔')
142
+
counter2=counter2+1# We are incrementing it to print value in below line
143
+
l2.config(text=f'{counter2} test passed ✔')# Dynamically change status label on GUI
132
144
133
145
ifflagCorrect==0:
134
-
msg="Stay Still. Minimum 8 Cases should pass"
146
+
msg="Stay Still. Minimum 8 Cases should pass"# Message to be spoken by Gtts
135
147
myobj=gTTS(text=msg, lang='en', slow='False')
136
148
137
149
try:
138
-
os.remove('msg.mp4')
150
+
os.remove('msg.mp4')# If for any reason this file exists remove it first and if it throws error simply print it
139
151
exceptExceptionase:
140
152
print(e)
141
153
142
-
myobj.save('msg.mp4')
143
-
playsound.playsound('msg.mp4')
144
-
os.remove('msg.mp4')
145
-
flagCorrect=1
154
+
myobj.save('msg.mp4') # Save audio file
155
+
playsound.playsound('msg.mp4') # Play it
156
+
os.remove('msg.mp4') # remove it
157
+
flagCorrect=1# Now setting Flag correct as 1, if flag is not 1 then sound will keep on playing
158
+
# What is confidence is less than 60%
146
159
else:
147
-
final_answer=False
148
-
final_answer_list.append(final_answer)
160
+
final_answer=False# Answer becomes false
161
+
final_answer_list.append(final_answer)# append to global list
149
162
#counter2=0
150
-
l2.config(text="❌Wrong Person❌")
151
-
winsound.PlaySound(None, winsound.SND_FILENAME)
163
+
l2.config(text="❌Wrong Person❌")# Dynamically change status label on GUI
164
+
winsound.PlaySound(None, winsound.SND_FILENAME)# Same like before dont play music
152
165
flagNoone=0
153
166
flagCorrect=0
154
167
@@ -164,14 +177,14 @@ def detect():
164
177
myobj.save('msg.mp4')
165
178
playsound.playsound('msg.mp4')
166
179
os.remove('msg.mp4')
167
-
flagWrong=1
168
-
180
+
flagWrong=1# Above lines are same like before
169
181
170
182
183
+
# Exception occurs when no one is in front of screen since we have no another image to compare
171
184
exceptExceptionase:
172
185
#Blocking.blockinput()
173
186
174
-
l2.config(text="❖ No one is in front of the Screen. Screen is Locked ❖")
187
+
l2.config(text="❖ No one is in front of the Screen. Screen is Locked ❖")# Dynamically change status label on GUI
0 commit comments