-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathone_main_v3.py
1659 lines (1353 loc) · 82.4 KB
/
one_main_v3.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Imports
# ▄▄▄▌▐██▌█
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# it is to open text file in windows
import json
import os
# import time
from playsound import playsound
# it is to open text file in linux
import subprocess
# a simple GUI framework
import PySimpleGUI as sg
# to terminate the program on pressing exit button or window closing
from sys import exit
# to do operations on arrays of images
import numpy as np
# to read the live time
import times
# Image library help in reading images also creating images from arrays
from PIL import Image
# computer vision library to perform operations on images and videos
from cv2 import cv2
# keras implementation of facenet
from keras_facenet import FaceNet
# to expand dimensions
from keras.backend import expand_dims
# to calculate distances bw embeddings
from scipy.spatial.distance import cosine
# to read the monitors an obtain screen sizes
from screeninfo import get_monitors
import smtplib
import ssl
import random
from credentials import get_email, get_password
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Some variables
# ▄▄▄▌▐██▌█
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# getting screen size
width= get_monitors()[0].width
height= get_monitors()[0].height
screensize=(int(width), int(height))
print("[INFO] Reading screen size\n[INFO] size set to: ", screensize, "Type of: ", type(screensize))
# to carry addresses of picture and video file
vid_url, pic_url= "",""
# it is to carry total frames from first read by cv2
total_frames = 0
# initializing these so any sub function can access that
picture_input, video_input, person_name ="", "", "Anonymous"
# setting defaults
threshold, v_fps, fps, frame_count, duration =0.5,1,1,0,0
alarm = False
alarm_sound = "Alarm.mp3"
v_out, v_show, video_file= False, False, True
# when estimating the time to take by process this ration can be
# multiplied with video duration when 1 vfps otherwise it change
aprx_ratio= 0.75
time = (duration * aprx_ratio) + 10
#to check first loop in GUI, for fetching results message in middle column
first = 0
# video source conditional check default 0 indicate video file
video_source_changing=0
# default divisible and tolerance
divisible = 0
tolerance = 5
# Loading model
encodder = FaceNet()
module_path = os.path.dirname(os.path.realpath(__file__))
result_time_string=""
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ GUI variable
# ▄▄▄▌▐██▌█ carrying fonts, size etc
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# to use in padding tuple
general_size= (int(width/90), 1)
output_height=int(height/18)
output_width=int(width/3)
result_height=int(height/25)
inputs_pad_standard= ((5,5),2)
setting_pad= ((5,5), (1,1))
login_pad= (5,10)
login_had1= "Akira 30"
login_had2= "Akira 25"
login_had3= "Akira 20"
login_had4= "Akira 14"
popups_font= "Akira 14"
h1= "Akira 30"
h2= "Akira 25"
h3= "Akira 10"
h33= "Akira 15"
# theme
sg.theme('dark grey 5')
#________________________________________________________________
# product keys
available_product_keys= ["1FARZAN9", "2FAHAD99", "3FAROOQ9"]
#________________________________________________________________
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Some functions
# ▄▄▄▌▐██▌█
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
def get_embedding(face):
# face = expand_dims(face, axis=0)
embeddings = encodder.embeddings(np.array(face))
return embeddings
def info_encoder(pss):
evalue = []
for char in pss:
evalue.append(ord(char))
return evalue
def info_decoder(evalue):
pss = ''
for val in evalue:
pss = pss + chr(val)
return str(pss)
def send_otp(otp, email):
try:
port = 465
sender_email = get_email()
sender_email_pass = get_password()
context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com', port, context=context) as server:
server.login(sender_email, sender_email_pass)
message = ('Your OTP is {}').format(otp)
message = 'Subject: {}\n\n{}'.format("OTP", message)
server.sendmail(sender_email, email, message)
return
except Exception as err:
sg.Popup(err)
return
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ GUI screens
# ▄▄▄▌▐██▌█ in functions
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# login window
def launch_login_window():
# layout =
layout=[
[sg.Text('Login', font=login_had1, pad=((5,5),(200,20)))],
[sg.Text('User Name: ', font=login_had3, pad=login_pad, size=(16, 1)), sg.In(font=login_had3, size=(16,1), key="-LGUSER-")],
[sg.Text('Password: ', font=login_had3, size=(16, 1), pad=login_pad), sg.In(password_char="*", size= (16,1), font=login_had3, key="-LGPASS-")],
[sg.Button('Login', key="-LOGINBTN-", pad=login_pad, font=login_had4), sg.Button('Forget Password', key="-FORGET-", pad=login_pad, font=login_had4)],
[sg.T("\n\n\n\nNot Registered?", font=h2, pad=login_pad)],
[sg.Button("Register Now", key='-REGBTN-', font=login_had4, pad=login_pad), sg.Button('Exit', key="-LOGEXIT-", font=login_had4)]
]
in_col=[[sg.Column(layout, element_justification="l", vertical_alignment="center")]]
return sg.Window('Login - InViDet', in_col, location=(0,0), element_justification="c", size=screensize, finalize=True)
# register window
def launch_register_window():
layout = [[sg.Text('Registration', font=login_had1, pad=((5,5), (200,20)))],
[sg.T("\nEnter 8 digit product key", font=login_had4, pad=login_pad)],
[sg.Input(size=(35,1),key='-PRDCT-', font=login_had3, pad=login_pad, enable_events=True)],
[sg.Button('Verify', pad=((5, 20), 10), font=login_had4, key="-VERIFY-", disabled= True)],
[sg.T("Email", font=login_had3, size=(18, 1)),sg.Input(size=(16, 1), key='-EMAIL-', font=login_had3, pad=login_pad, disabled= True)],
[sg.T("User Name", font=login_had3, size=(18,1)), sg.Input(size=(16,1),key='-SETUSERNAME-', font=login_had3, pad=login_pad, disabled= True)],
[sg.T("Password", font=login_had3, size=(18,1)), sg.Input(size=(16,1),key='-SETPASS-', font=login_had3, pad=login_pad, password_char="*", disabled= True)],
[sg.T("Re-Enter Password", font=login_had3, size=(18, 1)), sg.Input(size=(16, 1), key='-SETPASS1-', font=login_had3, pad=login_pad, password_char="*", disabled= True)],
[sg.Button('Register', pad=((5,20),10), font=login_had4, key="-REGOK-", disabled= True)],
[sg.Button('Login Now', key="-BKLOGIN-", font=login_had4, pad=login_pad), sg.Button('Exit', key="-REGEXIT-", font=login_had4, pad=login_pad)]]
in_col=[[sg.Col(layout, element_justification="l", vertical_alignment="c")]]
return sg.Window('Register - InViDet', in_col,location=(0,0), element_justification="c", size=screensize, finalize=True)
# main program window
def launch_main_window():
title_layout = [[
sg.Text('InVid Detector', justification='center', font=h1)
]]
left_inputs_setting_col = [
# picture_video_selection_layout
[sg.T("Inputs", font=h2, pad=inputs_pad_standard, size= general_size)],
[sg.T('Select Picture', pad=inputs_pad_standard, key="-SPIC-", size=(20, 1), font=h33),
sg.In(key='-PICIN-', pad=inputs_pad_standard, visible=False),
sg.FilesBrowse(target='-PICIN-', pad=inputs_pad_standard, key="-PBRS-", )],
[sg.T('Select Video', pad=inputs_pad_standard, key="-SVID-", size=(20, 1), font=h33),
sg.In(key='-VIDIN-', pad=inputs_pad_standard, visible=False),
sg.FilesBrowse(target='-VIDIN-', pad=((5, 5), (2, 15)), disabled=False, key="-VBRS-", )],
# input_details_layout
[sg.T("Details on input", pad=setting_pad, font=h33, size=(24, 1))],
[sg.T("Picture name: ", pad=setting_pad, font=h3, key="-PNAME-", size=(24, 1))],
[sg.T("Video name: ", pad=setting_pad, font=h3, key="-VNAME", size=(24, 1))],
[sg.T("Video frame rate: ", pad=setting_pad, font=h3, key="-VFPS-", size=(24, 1))],
[sg.T("Video duration: ", pad=setting_pad, font=h3, key="-VDUR-", size=(24, 1))],
# button for load
[sg.B("Load Inputs", key="-LOAD-", pad=((5, 5), (1, 10))),
sg.Radio("Cam Stream", "RADIO5", enable_events=True, font=h3, pad=(0, 0), size=(12, 1), key="-VIN1-"),
sg.Radio("Video File", "RADIO5", enable_events=True, default=True, font=h3, pad=(0, 0), size=(12, 1),
key="-VIN2-")],
# person_name_layout
[sg.HSeparator()],
[sg.T("Setting", font=h2, pad=setting_pad)],
[sg.Text("Person Name", pad=setting_pad, font=h33),
sg.Input(key="-PRNAME-", size=(10, 1), pad=setting_pad, font=h33, enable_events=True),
sg.Text("(Optional)", pad=setting_pad, font=h3) ],
# threshold_layout
[sg.T("Threshold", pad=setting_pad, font=h33)],
[sg.Radio('0.4', "RADIO1", size=(4, 1), pad=setting_pad, font=h3, key="-TH1-", enable_events=True),
sg.Radio('0.5', "RADIO1", default=True, size=(4, 1), pad=setting_pad, font=h3, key="-TH2-", enable_events=True),
sg.Radio('0.6', "RADIO1", size=(4, 1), pad=setting_pad, font=h3, key="-TH3-", enable_events=True),
sg.Radio('0.7', "RADIO1", size=(4, 1), pad=setting_pad, font=h3, key="-TH4-", enable_events=True)],
# verifying_layout
[sg.T("Verifying Rate", pad=setting_pad, font=h33)],
[sg.Radio("V1FPS", "RADIO2", default=True, font=h3, pad=setting_pad, size=(6, 1), key="-FPS1-", enable_events=True),
sg.Radio("V2FPS", "RADIO2", font=h3, pad=setting_pad, size=(6, 1), key="-FPS2-", enable_events=True)],
[sg.Radio("V3FPS", "RADIO2", font=h3, pad=setting_pad, size=(6, 1), key="-FPS3-", enable_events=True),
sg.Radio("V4FPS", "RADIO2", font=h3, pad=setting_pad, size=(6, 1), key="-FPS4-", enable_events=True)],
# write_video_layout
[sg.T("Video Out", pad=setting_pad, font=h33)],
[sg.Radio("No", "RADIO3", default=True, font=h3, pad=setting_pad, size=(6, 1), key="-VOUT1-", enable_events=True),
sg.Radio("Yes", "RADIO3", font=h3, pad=setting_pad, size=(6, 1), key="-VOUT2-", enable_events=True)],
[sg.T("Video Display", pad=setting_pad, font=h33)],
[sg.Radio("No", "RADIO4", default=True, font=h3, pad=setting_pad, size=(6, 1), key="-VSHOW1-", enable_events=True),
sg.Radio("Yes", "RADIO4", font=h3, pad=setting_pad, size=(6, 1), key="-VSHOW2-", enable_events=True)],
# alarm
[sg.T("Alarm On Recognition", pad=setting_pad, font=h33)],
[sg.Radio("OFF", "RADIO6", default=True, font=h3, pad=setting_pad, size=(6, 1), key="-ALARM1-", enable_events=True),
sg.Radio("ON", "RADIO6", font=h3, pad=setting_pad, size=(6, 1), key="-ALARM2-", enable_events=True)],
# horisotal
[sg.HSeparator()],
# set_choice_layout
[sg.T("Threshold\t: 0.5 (default)", pad=setting_pad, font=h3, key="-DFLT1-", size=(30, 1))],
[sg.T("Verify Rate\t: 1FPS (default)", pad=setting_pad, font=h3, key="-DFLT2-", size=(30, 1))],
[sg.T("Video Out\t: NO (default)", pad=setting_pad, font=h3, key="-DFLT3-", size=(30, 1))],
[sg.T("Video Display\t: NO (default)", pad=setting_pad, font=h3, key="-DFLT4-", size=(30, 1))],
# aprx time to process
[sg.T("Estimated time to process: ", pad=setting_pad, font=h3, key="-APRX-", size=(28, 1))],
# buttons Start, logout, exit
[sg.B("Start Processing", key='-START-', pad=setting_pad, font=h3, disabled=True),
sg.B("Logout", key='-LOGOUT-', pad=setting_pad, font=h3),
sg.B("Exit", key='-MAINEXIT-', pad=setting_pad, font=h3),
sg.T("Error! Inputs Can't Load", font=h3, visible=False, key="-ERR-", text_color="red")]
]
# right column that carry output logs
right_col = [
[sg.T("Output Logs", font=h2, pad=inputs_pad_standard)],
[sg.Output(size=(output_width,output_height))]
]
# middle column that carry Results
mid_column = [
[sg.T("Final Results", font=h2, pad=inputs_pad_standard)],
[sg.T("Time Elapsed: ", visible=False, font=h3, key="-TIME-")],
[sg.T("Results", key="-RES-", size=(output_width,result_height), font=h3)],
[sg.B("Show Results", key="-SHOW-", font=h3), sg.B("Clear Results", key="-CLEAR-", font=h3)]
]
# final layout/ integrated layout
layout = [
[sg.Column(title_layout, element_justification='center', pad=((int(width/2-150), 0), 1))],
[sg.HSeparator()],
[sg.Column(left_inputs_setting_col, element_justification="left", size=(int(width/3-150),height)), sg.VSeperator(),
sg.Col(mid_column, element_justification="left", size=(int(width/3),height)), sg.VSeperator(),
sg.Column(right_col, element_justification="left", size=(int(width/3),height))]
]
# starting windows
print("[INFO] Launching main winow")
return sg.Window('Home - InViDet', layout, location=(0,0), size=screensize, finalize=True)
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Launching 1st window
# ▄▄▄▌▐██▌█ and HANDLING EVENTS
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# start off with 1 window open
login_window, register_window, main_window = launch_login_window(), None, None
# Event Loop
while True:
window, event, values = sg.read_all_windows()
# handling when exit button clicked or closing window
if event == sg.WIN_CLOSED or event in ["-LOGEXIT-" ,"-REGEXIT-", "-MAINEXIT-"]:
if window == register_window:
window.close()
register_window = None
if window == main_window:
window.close()
main_window = None
if window == login_window:
login_window = None
window.close()
# finally exit program in any case
exit()
# taking control to main window, if successfully login
if event == "-LOGINBTN-" and not register_window and not main_window:
# reg_email = values["-EMAIL-"]
login_user_name = values["-LGUSER-"]
login_password = values["-LGPASS-"]
# reg_repassword = values["-SETPASS1-"]
# check on all required fields must be filled
if not login_user_name or not login_password:
sg.popup_error("Missing Fields!", font=popups_font, title="Error")
continue
# check on usernames and passwords must not contain spaces
if (" " in login_user_name):
sg.popup_error("User Name can't contain spaces!", font=popups_font, title="Error")
continue
if (" " in login_password):
sg.popup_error("Password can't contain spaces!", font=popups_font, title="Error")
continue
# check on password length (pass: 8-15)
if len(login_user_name) < 5 or len(login_user_name) > 10:
sg.popup_error("Password must be 5 to 10 characters long", font=popups_font, title="Error")
continue
# check on password length (pass: 8-15)
if len(login_password) < 8 or len(login_password) > 15:
sg.popup_error("Password must be 8 to 15 characters long", font=popups_font, title="Error")
continue
# some sort of information encryption (manipulation with the asci values)
# encrypted_reg_email = info_encoder(reg_email)
# encrypted_reg_user_name = info_encoder(reg_user_name)
# encrypted_reg_password = info_encoder(reg_password)
with open('invidet_data.py', 'r') as read_data:
user_data_dictionary = json.load(read_data)
decrypted_username = info_decoder(user_data_dictionary["username"])
decrypted_password = info_decoder(user_data_dictionary["password"])
if login_user_name != decrypted_username:
sg.popup("User is not registered!", font=popups_font, title="Error")
continue
if login_password != decrypted_password:
sg.popup("Wrong Password!", font=popups_font, title="Error")
continue
# # finally writing information in file to use later
# user_data_dictionary = {"email": encrypted_reg_email, "username": encrypted_reg_user_name,
# "password": encrypted_reg_password}
# dic.update({'sqs': False})
with open('invidet_data.py', 'w') as write:
json.dump(user_data_dictionary, write)
sg.popup("Successfully Logged-in!", non_blocking= True, auto_close_duration= 5, auto_close= True, keep_on_top=True, title="Success")
main_window = launch_main_window()
login_window.close()
login_window = None
register_window = None
# handling popup event if clicked forget password
if event == "-FORGET-":
entered_email = sg.popup_get_text('Enter your email address', 'Forget Password', size=(20, 3),
font=popups_font, title="Error")
# bugfix screen hang when it enter nothing
if not entered_email:
continue
with open("invidet_data.py", "r") as read_data:
user_data_dictionary = json.load(read_data)
decrypted_email = info_decoder(user_data_dictionary["email"])
entered_email = entered_email.lower()
if entered_email != decrypted_email:
sg.popup_error("Your entered email is not in registered record", title="Error")
continue
generated_otp = random.randint(111111, 999999)
print("otp: ", generated_otp)
sg.popup_timed("Check your mail, and fetch OTP: "+ str(entered_email), auto_close_duration=5, keep_on_top= True, title="Fetech OTP")
send_otp(generated_otp, entered_email)
entered_otp = sg.popup_get_text('Enter OTP', 'Forget Password', size=(20, 3), font=popups_font, keep_on_top= True)
if str(generated_otp) != str(entered_otp):
sg.popup_error("OTP is wrong! exiting", title="Error")
continue
sg.popup('Remember Credentials!', 'User Name: ' + str(info_decoder(user_data_dictionary["username"])),
"Password: " + str(info_decoder(user_data_dictionary["password"])), font=popups_font, keep_on_top= True, title="User Details")
# taking control to Registration screen, when clicked register now
if event == '-REGBTN-' and not register_window and not main_window:
register_window = launch_register_window()
login_window.close()
login_window = None
main_window = None
# taking control back to login window, if successfully registered
if event == "-REGOK-":
reg_email = values["-EMAIL-"]
reg_user_name = values["-SETUSERNAME-"]
reg_password = values["-SETPASS-"]
reg_repassword = values["-SETPASS1-"]
# check on all required fields must be filled
if not reg_email or not reg_user_name or not reg_password or not reg_repassword:
sg.popup_error("Missing Fields!", font=popups_font, title="Error")
continue
# check on email and usernames and passwords must not contain spaces
if (" " in reg_email):
sg.popup_error("Email can't contain spaces!", font=popups_font, title="Error")
continue
if (" " in reg_user_name):
sg.popup_error("User Name can't contain spaces!", font=popups_font, title="Error")
continue
if (" " in reg_password or " " in reg_repassword):
sg.popup_error("Password can't contain spaces!", font=popups_font, title="Error")
continue
# check on email validity
if not reg_email.endswith("@gmail.com"):
sg.popup_error("Email is not valid", font=popups_font, title="Error")
continue
# check on username length (validity 5-10)
if len(reg_user_name) < 5 or len(reg_user_name) > 10:
sg.popup_error("user name must be 5 to 10 characters long", font=popups_font, title="Error")
continue
# check on password length (validity 8-15)
if len(reg_password) < 8 or len(reg_password) > 15 or len(reg_repassword) < 8 or len(reg_repassword) > 15:
sg.popup_error("Password must be 8 to 15 characters long", font=popups_font, title="Error")
continue
# check on password match
if not reg_password == reg_repassword:
sg.popup_error("Password doesn't match!", font=popups_font, title="Error")
continue
# some sort of information encryption (manipulation with the asci values)
encrypted_reg_email = info_encoder(reg_email)
encrypted_reg_user_name = info_encoder(reg_user_name)
encrypted_reg_password = info_encoder(reg_password)
# finally writing information in file to use later
user_data_dictionary = {"email": encrypted_reg_email, "username": encrypted_reg_user_name,
"password": encrypted_reg_password}
# dic.update({'sqs': False})
with open('invidet_data.py', 'w') as write:
json.dump(user_data_dictionary, write)
sg.popup("Successfully Registered!", font=popups_font)
# making these fields disabled again so not everyone can register himself
window["-REGOK-"].update(disabled=True)
window["-EMAIL-"].update(disabled=True)
window["-SETUSERNAME-"].update(disabled=True)
window["-SETPASS-"].update(disabled=True)
window["-SETPASS1-"].update(disabled=True)
# closing and launching new windows
login_window = launch_login_window()
register_window.close()
register_window = None
main_window = None
# taking back to login screen, clicked login now, from register screen
if event == "-BKLOGIN-" and not login_window and not main_window:
login_window = launch_login_window()
register_window.close()
register_window = None
main_window = None
# handling verification with available product keys
if event == "-VERIFY-":
# obtaining product key from user
product_key= values["-PRDCT-"]
# matching the key if available
if product_key in available_product_keys:
window["-REGOK-"].update(disabled= False)
window["-EMAIL-"].update(disabled= False)
window["-SETUSERNAME-"].update(disabled= False)
window["-SETPASS-"].update(disabled= False)
window["-SETPASS1-"].update(disabled= False)
sg.popup("Successfully Verified!\nNow you can create account", font= popups_font, title="Verified", auto_close= True, auto_close_duration= 3)
else:
sg.popup_error("Product key is not valid", font= popups_font, title="Error")
continue
# handling to force 8 characters key
if event == "-PRDCT-":
product_key = values["-PRDCT-"]
if len(product_key) == 8:
window["-VERIFY-"].update(disabled=False)
else:
window["-VERIFY-"].update(disabled=True)
# taking control back to login window, if successfully registered
if event == "-REGOK-":
login_window = launch_login_window()
register_window.close()
register_window = None
main_window = None
# taking control back to login window, if logout, from main window
if event == "-LOGOUT-":
login_window = launch_login_window()
main_window.close()
register_window = None
main_window = None
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Load inputs
# ▄▄▄▌▐██▌█ in HANDLING EVENTS
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# handling video source choice
# if cam stream
if event == "-VIN1-":
if video_source_changing == 1:
continue # doing it so that it wont monitor every click, only monitor first click to cam stream or video file
# emptying video variable as well as video input sources when it clicked second time,
# coming back from cam stream, to specifically asked the user to select new video
# dont rely on previous video choices
video_input=""
window["-VIDIN-"].update("")
video_file=False
print("[INFO] Video source changed to Cam Stream")
window["-SVID-"].update("Select Video")
window["-VNAME"].update(value="Video name: ")
window["-VFPS-"].update(value="Video frame rate:" )
window["-VDUR-"].update(value="Video duration: ")
window["-VBRS-"].update(disabled=True)
try:
cam = cv2.VideoCapture(0)
fps = int(cam.get(5))
print("fps:", fps)
cam.release()
cv2.destroyAllWindows()
except:
print("[ERROR] Live Stream is unable to read")
print("[ERROR] Permission Denied!")
break
video_source_changing=1
# if cam stream it should be able to perform, dont wait for video input as
# source has changed to cam stream and picture is loaded
# start button now enabled
if not video_file and len(picture_input)>0:
window["-START-"].update(disabled=False)
# if video file
if event == "-VIN2-":
if video_source_changing == 0:
continue # doing it so that it wont monitor every click, only monitor first click to cam stream or video file
# start became disabled again if no source video, unless there is video file loaded
if video_input == "":
window["-START-"].update(disabled= True)
video_file=True
print("[INFO] Video source changed to video file on disc")
window["-VBRS-"].update(disabled=False)
video_source_changing=0
# load button, it verify extension and fill the address carrying variables picture_input or video_input
if event == '-LOAD-':
picture_input = values["-PICIN-"]
video_input = values["-VIDIN-"]
window.refresh()
# if brows button returned some string of address, it length would be greater than 0
if len(picture_input) > 0:
image_extension = picture_input.rsplit(".", 1)[1]
# check on extension
if image_extension not in ["tif", "tiff", "bmp", "jpg", "jpeg", "gif", "png", "esp"]:
print(
"[ERROR] Image file extension is not known\n[ERROR] Check Image path, chose again with known image\n[ERROR] extensions instead of .%s" % image_extension)
window["-SPIC-"].update("Picture Error")
continue
print("[INFO] Picture is loaded")
window["-SPIC-"].update("Picture SELECTED")
pic_name = picture_input.rsplit("/", 1)
pic_name = "Picture name: %s" % pic_name[1]
window["-PNAME-"].update(value=str(pic_name))
else:
print("[WARN] Picture is MISSING")
window.refresh()
if len(video_input) > 0:
video_extension = video_input.rsplit(".", 1)[1]
# check on extension
if video_extension not in ["mp4", "MP4", "MOV", "mov", "WMV", "wmv", "FLV", "flv", "AVI", "avi",
"AVCHD", "avchd", "WebM", "webm", "MKV", "mkv"]:
print(
"[ERROR] Video file extension is not known\n[ERROR] Check Video path, chose again with known Video\n"
"[ERROR] extensions instead of .%s" % video_extension)
window["-SVID-"].update("Video Error")
continue
print("[INFO] Video is loaded")
window["-SVID-"].update("Video SELECTED")
# obtaining fps and setting text
vid_url = video_input.rsplit(module_path, 1)
vid_url = vid_url[1][1:]
# print(vid_url)
cap = cv2.VideoCapture(vid_url)
fps = int(cap.get(5))
print("[INFO] fps of selected video", fps)
frame_count = int(cap.get(7))
cap.release()
cv2.destroyAllWindows()
print("[INFO] Total frames of selected video", frame_count)
# clip= VideoFileClip(vid_url)
# duration= clip.duration
sec = int(frame_count / fps)
min = int(sec / 60)
sec = int(sec % 60)
hr = int(min / 60)
min = int(min % 60)
# int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
# getting/setting estimated duration
video_duration_string = "Video duration: " + str(hr) + ":" + str(min) + ":" + str(sec)
est_sec = int(frame_count / fps * aprx_ratio + 10)
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(
est_sec)
window["-APRX-"].update(estimated_time_string)
# if time_s > 60:
# time_m = time_s / 60
# window["-APRX-"].update("Estimated time to process: %s min" % str(time_m)[0:4])
# if time_m > 60:
# time_h = time_m / 60
# window["-APRX-"].update("Estimated time to process: %s hour" % str(time_h)[0:4])
vid_name = vid_url.rsplit("/", 1)
# print(vid_name, pic_url)
vid_name = f'{"Video name: "}{vid_name[1]}'
message_fps = "Video frame rate: %s" % fps
# print(vid_name, fps, pic_url)
# window.refresh()
window["-VNAME"].update(value=vid_name)
window["-VFPS-"].update(value=message_fps)
window["-VDUR-"].update(value=video_duration_string)
else:
# start button back to disabled if video input missing
if video_file:
window["-START-"].update(disabled=True)
print("[WARN] Video is MISSING")
# window.refresh()
if len(picture_input) > 0 and len(video_input) > 0:
print("[INFO] Inputs are loaded successfully")
window["-START-"].update(disabled=False)
window["-ERR-"].update(visible=False)
window.refresh()
if not video_file and len(picture_input) > 0:
print("[INFO] Inputs are loaded successfully")
window["-START-"].update(disabled=False)
window["-ERR-"].update(visible=False)
window.refresh()
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Setting
# ▄▄▄▌▐██▌█ in HANDLING EVENTS
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
# ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
# handling threshold choices
if event== "-TH1-":
window["-DFLT1-"].update("Set Threshold\t: 0.4")
threshold = 0.4
print("[INFO] Thresholds: ", threshold)
if event == "-TH2-":
window["-DFLT1-"].update("Set Threshold\t: 0.5 (default)")
threshold = 0.5
print("[INFO] Thresholds: ", threshold)
if event == "-TH3-":
window["-DFLT1-"].update("Set Threshold\t: 0.6")
threshold = 0.6
print("[INFO] Thresholds: ", threshold)
if event == "-TH4-":
window["-DFLT1-"].update("Set Threshold\t: 0.7")
threshold = 0.7
print("[INFO] Thresholds: ", threshold)
# setting vfps
if event == "-FPS1-":
window["-DFLT2-"].update("Verify Frame Rate\t: 1FPS (default)")
# updating time estomation based on choice
aprx_ratio = 0.75
est_sec = int(frame_count / fps * aprx_ratio + 10)
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(est_sec)
window["-APRX-"].update(estimated_time_string)
# setting verifying fps
v_fps = 1
print("[INFO] FPS: ", v_fps)
print("[INFO] Estimated time to process: ", (duration* aprx_ratio)+10, "seconds") # 0.75 is ratio on my pc for v1FPS +10 tensor flow loading delay
if event == "-FPS2-":
window["-DFLT2-"].update("Verify Frame Rate\t: 2FPS")
# updating time estomation based on choice
aprx_ratio = 1.5
est_sec = int(frame_count / fps * aprx_ratio + 10)
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(est_sec)
window["-APRX-"].update(estimated_time_string)
# setting verifying fps
v_fps = 2
print("[INFO] FPS: ", v_fps)
print("[INFO] Estimated time to process: ", (duration* aprx_ratio)+10, "seconds") # 0.75 is ratio on my pc for v1FPS +10 tensor flow loading delay
if event == "-FPS3-":
window["-DFLT2-"].update("Verify Frame Rate\t: 3FPS")
# updating time estomation based on choice
aprx_ratio = 2.25
est_sec = int(frame_count / fps * aprx_ratio + 10)
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(est_sec)
window["-APRX-"].update(estimated_time_string)
# setting verifying fps
v_fps = 3
print("[INFO] FPS: ", v_fps)
print("[INFO] Estimated time to process: ", (duration* aprx_ratio)+10, "seconds") # 0.75 is ratio on my pc for v1FPS +10 tensor flow loading delay
if event == "-FPS4-":
window["-DFLT2-"].update("Verify Frame Rate\t: 4FPS")
# updating time estomation based on choice
aprx_ratio = 3
est_sec = int(frame_count / fps * aprx_ratio + 10)
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(est_sec)
window["-APRX-"].update(estimated_time_string)
# setting verifying fps
v_fps = 4
print("[INFO] FPS: ", v_fps)
print("[INFO] Estimated time to process: ", (duration* aprx_ratio)+10, "seconds") # 0.75 is ratio on my pc for v1FPS +10 tensor flow loading delay
# setting video write options
if event == "-VOUT1-":
window["-DFLT3-"].update("Write Video\t: NO (default)")
v_out = False
print("[INFO] Video OUT: ", v_out)
if event == "-VOUT2-":
window["-DFLT3-"].update("Write Video\t: YES")
v_out = True
print("[INFO] Video OUT: ", v_out)
# setting Video show options
if event == "-VSHOW1-":
window["-DFLT4-"].update("Show Video\t: NO (default)")
v_show = False
print("[INFO] Video SHOW: ", v_show)
# showing video may cause a little delay so updating it
est_sec = int(frame_count / fps * aprx_ratio + 10)
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(est_sec)
window["-APRX-"].update(estimated_time_string)
if event == "-VSHOW2-":
window["-DFLT4-"].update("Show Video\t: YES")
v_show = True
print("[INFO] Video SHOW: ", v_show)
# showing video may cause a little delay so updating it
est_sec = int(frame_count / fps * aprx_ratio *1.05 + 10)
# 1.05 approximately delay ratio for showing vs not showing
est_min = int(est_sec / 60)
est_sec = int(est_sec % 60)
est_hr = int(est_min / 60)
est_min = int(est_min % 60)
estimated_time_string = "Estimated time to process: " + str(est_hr) + ":" + str(est_min) + ":" + str(est_sec)
window["-APRX-"].update(estimated_time_string)
# setting alarm
if event == "-ALARM1-":
alarm = False
print("[INFO] Alarm is set to False")
if event == "-ALARM2-":
alarm =True
print("[INFO] Alarm is set to True")
# setting person name
if event == "-PRNAME-":
person_name= window["-PRNAME-"].get()
print("\n[INFO] Person name changed")
# opening result text file in default editor
if event == "-SHOW-":
# OS dependent for windows use OS library
# os.system("Final_Results_Invidet.txt")
subprocess.call(["xdg-open", "Output/"+person_name+"_final_results_at_"+result_time_string+".txt"])
# ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
# ───▄▄██▌█ Start Process
# ▄▄▄▌▐██▌█ in HANDLING EVENTS
# ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
# ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀(@)▀▘ ::
# ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
if event == "-START-":
if len(picture_input)<1:
print("[ERROR] Picture is not loaded yet")
window["-ERR-"].update(visible=True)
continue
else:
window["-ERR-"].update(visible=False)
if video_file and len(video_input)<1:
print("[ERROR] Video is not loaded yet")
window["-ERR-"].update(visible=True)
continue
else:
window["-ERR-"].update(visible=False)
window.refresh()
#__________________________________________________Internal Condition Where main logic on Start process actually start______________________________
if len(picture_input)>0 and (len(video_input)>0 or video_file==False):
if first>0:
window["-RES-"].update("Fetching new results")
print("[INFO] Fetching results for the ", first, " time")
first+= 1
else:
first += 1
print("[INFO] Fetching results for the ", first, " time")
print("[INFO] Starting process!")
print("[INFO] 10s delay on loading TensorFlow")
# to monitor how much time it took
process_start = times.now()
# __________________________________________________Break Point Start_____________________________________________________________________________________
# break point its initial where integration started for one_main_V3
# below call is no more needed
# track_records= compare_faces(picture_input, video_input, fps, threshold, v_fps, person_name, v_out, v_show, video_file)
# beloe is original compare function defination was this from face_compare module
#def compare_faces(pic_url, vid_url, fps, threshold, v_fps, person_name, v_out, v_show, video_file):
print("[INFO] Start processing")
# checking it is a cam stream, if it is, setting fps by self, not relying on cv2 to get fps from video file or else it raised exception modulo by zero
# bug fix 1.4
#
# second thoughts, No more need this bug fix as fps is being set for cam stream at the time
# changing video source option in event => VIN1 at line #380
# if video_file == False:
# fps = 30
# setting divisibe and tolerance based on vfps choice
print("[INFO] Calculating divisible based on suitable tolerance...")
if v_fps == 1:
divisible = fps
tolerance = 2
if v_fps == 2:
tolerance = 3
divisible = fps / 2
if v_fps == 3: