forked from navneeth594/Emotion_Recognition
/
gui.py
1005 lines (748 loc) · 29.5 KB
/
gui.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
from __future__ import division
import time
from tkinter import *
import cv2
import face_recognition
from PIL import ImageTk,Image
import numpy as geek
import tkinter.font as font
global window
window = Tk()
# to rename the title of the window
window.title("EMOTION RECOGNITION MODEL")
window.config(bg='grey')
global a
a=0
def work():
#from __future__ import division
import cv2
import time
from skimage import exposure
import threading
from scipy.misc import imsave
from urllib.request import urlopen
import cv2
import numpy as np
import tensorflow as tf
url='http://192.168.0.101:8080/shot.jpg'
def gen(frame):
import cv2
import math
import argparse
def highlightFace(net, frame, conf_threshold=0.7):
frameOpencvDnn=frame.copy()
frameHeight=frameOpencvDnn.shape[0]
frameWidth=frameOpencvDnn.shape[1]
blob=cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], True, False)
net.setInput(blob)
detections=net.forward()
faceBoxes=[]
for i in range(detections.shape[2]):
confidence=detections[0,0,i,2]
if confidence>conf_threshold:
x1=int(detections[0,0,i,3]*frameWidth)
y1=int(detections[0,0,i,4]*frameHeight)
x2=int(detections[0,0,i,5]*frameWidth)
y2=int(detections[0,0,i,6]*frameHeight)
faceBoxes.append([x1,y1,x2,y2])
cv2.rectangle(frameOpencvDnn, (x1,y1), (x2,y2), (0,255,0), int(round(frameHeight/150)), 8)
return frameOpencvDnn,faceBoxes
faceProto="opencv_face_detector.pbtxt"
faceModel="opencv_face_detector_uint8.pb"
ageProto="age_deploy.prototxt"
ageModel="age_net.caffemodel"
genderProto="gender_deploy.prototxt"
genderModel="gender_net.caffemodel"
MODEL_MEAN_VALUES=(78.4263377603, 87.7689143744, 114.895847746)
ageList=['(0-2)', '(4-6)', '(8-12)', '(15-20)', '(25-32)', '(38-43)', '(48-53)', '(60-100)']
genderList=['Male','Female']
faceNet=cv2.dnn.readNet(faceModel,faceProto)
ageNet=cv2.dnn.readNet(ageModel,ageProto)
genderNet=cv2.dnn.readNet(genderModel,genderProto)
padding=20
#while cv2.waitKey(1)<0 :
#hasFrame,frame=video.read()
resultImg,faceBoxes=highlightFace(faceNet,frame)
for faceBox in faceBoxes:
face=frame[max(0,faceBox[1]-padding):
min(faceBox[3]+padding,frame.shape[0]-1),max(0,faceBox[0]-padding)
:min(faceBox[2]+padding, frame.shape[1]-1)]
blob=cv2.dnn.blobFromImage(face, 1.0, (227,227), MODEL_MEAN_VALUES, swapRB=False)
genderNet.setInput(blob)
genderPreds=genderNet.forward()
gender=genderList[genderPreds[0].argmax()]
print(f'Gender: {gender}')
#print(type(f'{gender}'))
ageNet.setInput(blob)
agePreds=ageNet.forward()
age=ageList[agePreds[0].argmax()]
print(f'Age: {age[1:-1]} years')
#print(type(f'{age}'))
break
#cv2.imshow(frame)
#cv2.putText(resultImg, f'{gender}, {age}', (faceBox[0], faceBox[1]-10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0,50,50), 2, cv2.LINE_AA)
#cv2.imshow("Detecting age and gender",resultImg)
def violence(s):
import boto3
from botocore.client import Config
ACCESS_KEY_ID = ''
ACCESS_SECRET_KEY = ''
BUCKET_NAME = 'intelbucket'
data = open(s, 'rb')
s3 = boto3.resource(
's3',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=ACCESS_SECRET_KEY,
config=Config(signature_version='s3v4')
)
s3.Bucket(BUCKET_NAME).put_object(Key=s, Body=data)
def moderate_image(photo, bucket):
client=boto3.client('rekognition')
response = client.detect_moderation_labels(Image={'S3Object':{'Bucket':bucket,'Name':photo}})
#print(response)
print('Detected labels for ' + photo)
for label in response['ModerationLabels']:
print (label['Name'] + ' : ' + str(label['Confidence']))
#print (label['ParentName'])
return len(response['ModerationLabels'])
photo=s
bucket='intelbucket'
label_count=moderate_image(photo, bucket)
print("Labels detected: " + str(label_count))
if str(label_count)=='0':
print('No violence detected')
def show_webcam(vs) :
import datetime
import numpy as np
import pandas as pd
from time import time
from time import sleep
import re
import os
import math
import argparse
from collections import OrderedDict
### Image processing ###
from scipy.ndimage import zoom
from scipy.spatial import distance
import imutils
from scipy import ndimage
import dlib
from tensorflow.keras.models import load_model
from imutils import face_utils
import requests
global shape_x
global shape_y
global input_shape
global nClasses
from imutils import face_utils
from threading import Thread
import numpy as np
import playsound
import argparse
import imutils
import dlib
import simpleaudio as sa
shape_x = 48
shape_y = 48
input_shape = (shape_x, shape_y, 1)
nClasses = 7
thresh = 0.25
frame_check = 20
def prepare(filepath):
IMG_SIZE=150
img_array=cv2.imread(filepath,cv2.IMREAD_GRAYSCALE)
new_array=cv2.resize(img_array,(IMG_SIZE,IMG_SIZE))
return new_array.reshape(-1,IMG_SIZE,IMG_SIZE,1)
def sound_alarm():
filename = 'alarm.wav'
wave_obj = sa.WaveObject.from_wave_file(filename)
play_obj = wave_obj.play()
def eye_aspect_ratio(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
ear = (A + B) / (2.0 * C)
return ear
def detect_face(frame):
#Cascade classifier pre-trained model
cascPath = 'face_landmarks.dat'
faceCascade = cv2.CascadeClassifier(cascPath)
#BGR -> Gray conversion
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#Cascade MultiScale classifier
detected_faces = faceCascade.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=6,
minSize=(shape_x, shape_y),
flags=cv2.CASCADE_SCALE_IMAGE)
coord = []
for x, y, w, h in detected_faces :
if w > 100 :
sub_img=frame[y:y+h,x:x+w]
cv2.rectangle(frame,(x,y),(x+w,y+h),(0, 255,255),1)
coord.append([x,y,w,h])
return gray, detected_faces, coord
def extract_face_features(faces, offset_coefficients=(0.075, 0.05)):
gray = faces[0]
detected_face = faces[1]
new_face = []
for det in detected_face :
#Region dans laquelle la face est détectée
x, y, w, h = det
#X et y correspondent à la conversion en gris par gray, et w, h correspondent à la hauteur/largeur
#Offset coefficient, np.floor takes the lowest integer (delete border of the image)
horizontal_offset = np.int(np.floor(offset_coefficients[0] * w))
vertical_offset = np.int(np.floor(offset_coefficients[1] * h))
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#gray transforme l'image
extracted_face = gray[y+vertical_offset:y+h, x+horizontal_offset:x-horizontal_offset+w]
#Zoom sur la face extraite
new_extracted_face = zoom(extracted_face, (shape_x / extracted_face.shape[0],shape_y / extracted_face.shape[1]))
#cast type float
new_extracted_face = new_extracted_face.astype(np.float32)
#scale
new_extracted_face /= float(new_extracted_face.max())
#print(new_extracted_face)
new_face.append(new_extracted_face)
return new_face
EYE_AR_THRESH = 0.24
EYE_AR_CONSEC_FRAMES = 6
# initialize the frame counter as well as a boolean used to
# indicate if the alarm is going off
COUNTER = 0
ALARM_ON = False
# initialize dlib's face detector (HOG-based) and then create
# the facial landmark predictor
print("[INFO] loading facial landmark predictor...")
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
# grab the indexes of the facial landmarks for the left and
# right eye, respectively
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
(nStart, nEnd) = face_utils.FACIAL_LANDMARKS_IDXS["nose"]
(mStart, mEnd) = face_utils.FACIAL_LANDMARKS_IDXS["mouth"]
(jStart, jEnd) = face_utils.FACIAL_LANDMARKS_IDXS["jaw"]
(eblStart, eblEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eyebrow"]
(ebrStart, ebrEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eyebrow"]
model = load_model('video.h5')
face_detect = dlib.get_frontal_face_detector()
predictor_landmarks = dlib.shape_predictor("face_landmarks.dat")
nag=1
count=0
#Lancer la capture video
nav=0
prev=0
while True:
while True:
# Capture frame-by-frame
'''imageResp=urlopen(url)
imgNp=np.array(bytearray(imageResp.read()),dtype=np.uint8)
frame1=cv2.imdecode(imgNp,-1)'''
ret, frame1 = vs.read()
count=count+1
#frame = imutils.resize(frame1, width=450)
if int(str(datetime.datetime.now())[11]+str(datetime.datetime.now())[12])>=18:
frame = exposure.equalize_hist(frame1)
imsave('test2.jpg',frame1)
else:
cv2.imwrite('test2.jpg',frame1)
img1=cv2.imread('test2.jpg')
'''if nav==1:
gen(img1)
nav=0'''
gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
if count==1 or count==300:
violence('test2.jpg')
count=2
face_index = 0
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
rects = face_detect(gray, 1)
#gray, detected_faces, coord = detect_face(frame)
'''pres=len(rects)
if pres!=prev:
prev=pres
nav=1'''
# detect faces in the grayscale frame
#rects = detector(gray, 0)
for (i, rect) in enumerate(rects):
try:
shape = predictor_landmarks(gray, rect)
shape = face_utils.shape_to_np(shape)
# Identify face coordinates
(x, y, w, h) = face_utils.rect_to_bb(rect)
face = gray[y:y+h,x:x+w]
#Zoom on extracted face
face = zoom(face, (shape_x / face.shape[0],shape_y / face.shape[1]))
#Cast type float
face = face.astype(np.float32)
#Scale
face /= float(face.max())
face = np.reshape(face.flatten(), (1, 48, 48, 1))
#Make Prediction
prediction = model.predict(face)
prediction_result = np.argmax(prediction)
'''print("Angry : " + str(round(prediction[0][0],3)))
print("Disgust : " + str(round(prediction[0][1],3)))
print("Fear : " + str(round(prediction[0][2],3)))
print("Happy : " + str(round(prediction[0][3],3)))
print("Sad : " + str(round(prediction[0][4],3)))
print("Surprise : " + str(round(prediction[0][5],3)))
print("Neutral : " + str(round(prediction[0][6],3)))'''
# Rectangle around the face
'''cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.putText(frame, "Face #{}".format(i + 1), (x - 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
for (j, k) in shape:
cv2.circle(frame, (j, k), 1, (0, 0, 255), -1)'''
shape1 = predictor(gray, rect)
shape1 = face_utils.shape_to_np(shape1)
# extract the left and right eye coordinates, then use the
# coordinates to compute the eye aspect ratio for both eyes
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
# average the eye aspect ratio together for both eyes
ear = (leftEAR + rightEAR) / 2.0
#print(1)
# compute the convex hull for the left and right eye, then
# visualize each of the eyes
leftEyeHull = cv2.convexHull(leftEye)
rightEyeHull = cv2.convexHull(rightEye)
cv2.drawContours(img1, [leftEyeHull], -1, (0, 255, 0), 1)
cv2.drawContours(img1, [rightEyeHull], -1, (0, 255, 0), 1)
# check to see if the eye aspect ratio is below the blink
# threshold, and if so, increment the blink frame counter
if ear < EYE_AR_THRESH:
COUNTER += 1
#print(1)
# if the eyes were closed for a sufficient number of
# then sound the alarm
if COUNTER >= EYE_AR_CONSEC_FRAMES:
cv2.putText(img1, "DROWSINESS ALERT!", (10, 80),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
#print('drowsiness alert')
# if the alarm is not on, turn it on
if not ALARM_ON:
ALARM_ON = True
# check to see if an alarm file was supplied,
# and if so, start a thread to have the alarm
# sound played in the background
t = Thread(target=sound_alarm)
t.deamon = True
t.start()
#nag=1
# draw an alarm on the frame
# otherwise, the eye aspect ratio is not below the blink
# threshold, so reset the counter and alarm
else:
COUNTER = 0
ALARM_ON = False
'''
# 1. Add prediction probabilities
cv2.putText(frame, "----------------",(40,100 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 0)
cv2.putText(frame, "Emotional report : Face #" + str(i+1),(40,120 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 0)
cv2.putText(frame, "Angry : " + str(round(prediction[0][0],3)),(40,140 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 0)
cv2.putText(frame, "Disgust : " + str(round(prediction[0][1],3)),(40,160 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 0)
cv2.putText(frame, "Fear : " + str(round(prediction[0][2],3)),(40,180 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 1)
cv2.putText(frame, "Happy : " + str(round(prediction[0][3],3)),(40,200 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 1)
cv2.putText(frame, "Sad : " + str(round(prediction[0][4],3)),(40,220 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 1)
cv2.putText(frame, "Surprise : " + str(round(prediction[0][5],3)),(40,240 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 1)
cv2.putText(frame, "Neutral : " + str(round(prediction[0][6],3)),(40,260 + 180*i), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 155, 1)'''
# 2. Annotate main image with a label
if prediction_result == 0 :
cv2.putText(img1, "Angry",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
elif prediction_result == 1 :
cv2.putText(img1, "Disgust",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
elif prediction_result == 2 :
cv2.putText(img1, "Fear",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
elif prediction_result == 3 :
cv2.putText(img1, "Happy",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
elif prediction_result == 4 :
cv2.putText(img1, "Sad",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
elif prediction_result == 5 :
cv2.putText(img1, "Surprise",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
else :
cv2.putText(img1, "Neutral",(x+w-10,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# 3. Eye Detection and Blink Count
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
# Compute Eye Aspect Ratio
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
ear = (leftEAR + rightEAR) / 2.0
# And plot its contours
leftEyeHull = cv2.convexHull(leftEye)
rightEyeHull = cv2.convexHull(rightEye)
cv2.drawContours(img1, [leftEyeHull], -1, (0, 255, 0), 1)
cv2.drawContours(img1, [rightEyeHull], -1, (0, 255, 0), 1)
# 4. Detect Nose
nose = shape[nStart:nEnd]
noseHull = cv2.convexHull(nose)
cv2.drawContours(img1, [noseHull], -1, (0, 255, 0), 1)
# 5. Detect Mouth
mouth = shape[mStart:mEnd]
mouthHull = cv2.convexHull(mouth)
cv2.drawContours(img1, [mouthHull], -1, (0, 255, 0), 1)
# 6. Detect Jaw
jaw = shape[jStart:jEnd]
jawHull = cv2.convexHull(jaw)
cv2.drawContours(img1, [jawHull], -1, (0, 255, 0), 1)
# 7. Detect Eyebrows
ebr = shape[ebrStart:ebrEnd]
ebrHull = cv2.convexHull(ebr)
cv2.drawContours(img1, [ebrHull], -1, (0, 255, 0), 1)
ebl = shape[eblStart:eblEnd]
eblHull = cv2.convexHull(ebl)
cv2.drawContours(img1, [eblHull], -1, (0, 255, 0), 1)
'''modelx=tf.keras.models.load_model("64x3-CNN.model")
prediction=modelx.predict([prepare('test2.jpg')])
print(prediction)'''
except:
pass
cv2.putText(img1,'Number of Faces : ' + str(len(rects)),(40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, 155, 1)
cv2.imshow('Video', img1)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
vs.release()
break
#cv2.imshow('Video', img1)
# When everything is done, release the capture
#video_capture.release()
vs=cv2.VideoCapture(0)
show_webcam(vs)
def child_male(s,gender,age):
from PIL import ImageTk, Image
import webbrowser
def callback(url):
webbrowser.open_new(url)
newWindow = Toplevel(window)
newWindow.title("boys")
newWindow.geometry("300x300")
newWindow.configure(background='grey')
head=Label(newWindow,text='Top picks for you')
head.configure(font=('Courier',30))
head.place(x=800,y=0)
head2=Label(newWindow,text='Gender = '+gender)
head2.configure(font=('Courier',20))
head2.place(x=1350,y=720)
head3=Label(newWindow,text='Approximate age = '+age)
head3.configure(font=('Courier',20))
head3.place(x=1300,y=760)
ur_pic = s
ur_pic_img = Image.open(ur_pic)
ur_pic_img = ur_pic_img.resize((400,300), Image.ANTIALIAS)
ur_pic_photoImg = ImageTk.PhotoImage(ur_pic_img)
ur_pic_panel = Label(newWindow, image = ur_pic_photoImg)
ur_pic_panel.place(x=1250,y=400)
path = 'IMG-3630.jpg'
img = Image.open(path)
img = img.resize((400,300), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
panel = Label(newWindow, image = photoImg)
panel.place(x=100,y=50)
link = Label(newWindow, text="look out for more clothes", fg="blue", cursor="hand2")
link.place(x=550,y=200)
link.config(font=('Courier',20))
link.bind("<Button-1>", lambda e: callback("https://www.amazon.in/s?k=clothes+for+kids+boys&i=apparel&crid=34FBULXMLNYCS&sprefix=clothes+for+kids%2Capparel%2C292&ref=nb_sb_ss_ac-a-p_2_16"))
path1 = 'IMG_3644.jpg'
img1 = Image.open(path1)
img1 = img1.resize((400,300), Image.ANTIALIAS)
photoImg1= ImageTk.PhotoImage(img1)
panel1 = Label(newWindow, image = photoImg1)
panel1.place(x=100,y=410)
link1 = Label(newWindow, text="look out for more toys", fg="blue", cursor="hand2")
link1.place(x=550,y=550)
link1.config(font=('Courier',20))
link1.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=toys+for+kids+boys&ref=nb_sb_noss_1"))
path2 = 'IMG_3645.jpg'
img2 = Image.open(path2)
img2 = img2.resize((400,300), Image.ANTIALIAS)
photoImg2= ImageTk.PhotoImage(img2)
panel2 = Label(newWindow, image = photoImg2)
panel2.place(x=100,y=770)
link2 = Label(newWindow, text="look out for more watches", fg="blue", cursor="hand2")
link2.place(x=550,y=920)
link2.config(font=('Courier',20))
link2.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=watches+for+kids+boys&ref=nb_sb_noss_1"))
kill_button=Button(newWindow,text="Go back",command=newWindow.destroy)
kill_button.config(font=('Courier',20))
kill_button.place(x=1600,y=10)
newWindow.mainloop()
def child_female(s,gender,age):
from PIL import ImageTk, Image
import webbrowser
def callback(url):
webbrowser.open_new(url)
newWindow = Toplevel(window)
newWindow.title("girls")
newWindow.geometry("300x300")
newWindow.configure(background='grey')
head=Label(newWindow,text='Top picks for you')
head.configure(font=('Courier',30))
head.place(x=800,y=0)
head2=Label(newWindow,text='Gender = '+gender)
head2.configure(font=('Courier',20))
head2.place(x=1350,y=720)
head3=Label(newWindow,text='Approximate age = '+age)
head3.configure(font=('Courier',20))
head3.place(x=1300,y=760)
ur_pic = s
ur_pic_img = Image.open(ur_pic)
ur_pic_img = ur_pic_img.resize((400,300), Image.ANTIALIAS)
ur_pic_photoImg = ImageTk.PhotoImage(ur_pic_img)
ur_pic_panel = Label(newWindow, image = ur_pic_photoImg)
ur_pic_panel.place(x=1250,y=400)
path = 'IMG_3636.jpg'
img = Image.open(path)
img = img.resize((400,300), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
panel = Label(newWindow, image = photoImg)
panel.place(x=100,y=50)
link = Label(newWindow, text="look out for more clothes", fg="blue", cursor="hand2")
link.place(x=550,y=200)
link.config(font=('Courier',20))
link.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=clothes+for+girls+6-7+years+old&crid=1KH05VWM85166&sprefix=clothes+for+girls%2Caps%2C353&ref=nb_sb_ss_i_3_17"))
path1 = 'Kids-Makeup-Toys-Girls-Games-Baby-Cosmetics-Pretend-Play-Set-Hairdressing-Make-Up-Beauty-Toy-For.jpg'
img1 = Image.open(path1)
img1 = img1.resize((400,300), Image.ANTIALIAS)
photoImg1= ImageTk.PhotoImage(img1)
panel1 = Label(newWindow, image = photoImg1)
panel1.place(x=100,y=410)
link1 = Label(newWindow, text="look out for more toys", fg="blue", cursor="hand2")
link1.place(x=550,y=550)
link1.config(font=('Courier',20))
link1.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=toys+for+girls+6-7+years+old&ref=nb_sb_noss_2"))
path2 = 'paris-new-stylish-watch-for-girls-500x500.jpg'
img2 = Image.open(path2)
img2 = img2.resize((400,300), Image.ANTIALIAS)
photoImg2= ImageTk.PhotoImage(img2)
panel2 = Label(newWindow, image = photoImg2)
panel2.place(x=100,y=770)
link2 = Label(newWindow, text="look out for more watches", fg="blue", cursor="hand2")
link2.place(x=550,y=920)
link2.config(font=('Courier',20))
link2.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=watches+for+little+girls&crid=353KIC68L1ACS&sprefix=watches+for+%2Caps%2C351&ref=nb_sb_ss_i_4_12"))
kill_button=Button(newWindow,text="Go back",command=newWindow.destroy)
kill_button.config(font=('Courier',20))
kill_button.place(x=1600,y=10)
newWindow.mainloop()
def ad_male(s,gender,age):
from PIL import ImageTk, Image
import webbrowser
def callback(url):
webbrowser.open_new(url)
newWindow = Toplevel(window)
newWindow.title("Men")
newWindow.geometry("300x300")
newWindow.configure(background='grey')
head=Label(newWindow,text='Top picks for you')
head.configure(font=('Courier',30))
head.place(x=800,y=0)
head2=Label(newWindow,text='Gender = '+gender)
head2.configure(font=('Courier',20))
head2.place(x=1350,y=720)
head3=Label(newWindow,text='Approximate age = '+age)
head3.configure(font=('Courier',20))
head3.place(x=1300,y=760)
ur_pic = s
ur_pic_img = Image.open(ur_pic)
ur_pic_img = ur_pic_img.resize((400,300), Image.ANTIALIAS)
ur_pic_photoImg = ImageTk.PhotoImage(ur_pic_img)
ur_pic_panel = Label(newWindow, image = ur_pic_photoImg)
ur_pic_panel.place(x=1250,y=400)
path = 'IMG_3641.jpg'
img = Image.open(path)
img = img.resize((400,300), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
panel = Label(newWindow, image = photoImg)
panel.place(x=100,y=50)
link = Label(newWindow, text="look out for more clothes", fg="blue", cursor="hand2")
link.place(x=550,y=200)
link.config(font=('Courier',20))
link.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=clothes+for+men&ref=nb_sb_noss_1"))
path1 = 'watch.png'
img1 = Image.open(path1)
img1 = img1.resize((400,300), Image.ANTIALIAS)
photoImg1= ImageTk.PhotoImage(img1)
panel1 = Label(newWindow, image = photoImg1)
panel1.place(x=100,y=410)
link1 = Label(newWindow, text="look out for more watches", fg="blue", cursor="hand2")
link1.place(x=550,y=550)
link1.config(font=('Courier',20))
link1.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=watches+for+men&crid=27TRXYHRP4RH3&sprefix=watches+%2Caps%2C346&ref=nb_sb_ss_i_1_8"))
path2 = 'men-s-sport-shoes-500x500.jpg'
img2 = Image.open(path2)
img2 = img2.resize((400,300), Image.ANTIALIAS)
photoImg2= ImageTk.PhotoImage(img2)
panel2 = Label(newWindow, image = photoImg2)
panel2.place(x=100,y=770)
link2 = Label(newWindow, text="look out for more shoes", fg="blue", cursor="hand2")
link2.place(x=550,y=920)
link2.config(font=('Courier',20))
link2.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=shoes+for+men&ref=nb_sb_noss_1"))
kill_button=Button(newWindow,text="Go back",command=newWindow.destroy)
kill_button.config(font=('Courier',20))
kill_button.place(x=1600,y=10)
newWindow.mainloop()
def ad_female(s,gender,age):
from PIL import ImageTk, Image
import webbrowser
def callback(url):
webbrowser.open_new(url)
newWindow = Toplevel(window)
newWindow.title("women")
newWindow.geometry("300x300")
newWindow.configure(background='grey')
head=Label(newWindow,text='Top picks for you')
head.configure(font=('Courier',30))
head.place(x=800,y=0)
head2=Label(newWindow,text='Gender = '+gender)
head2.configure(font=('Courier',20))
head2.place(x=1350,y=720)
head3=Label(newWindow,text='Approximate age = '+age)
head3.configure(font=('Courier',20))
head3.place(x=1300,y=760)
ur_pic = s
ur_pic_img = Image.open(ur_pic)
ur_pic_img = ur_pic_img.resize((400,300), Image.ANTIALIAS)
ur_pic_photoImg = ImageTk.PhotoImage(ur_pic_img)
ur_pic_panel = Label(newWindow, image = ur_pic_photoImg)
ur_pic_panel.place(x=1250,y=400)
path = '2.jpg'
img = Image.open(path)
img = img.resize((400,300), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
panel = Label(newWindow, image = photoImg)
panel.place(x=100,y=50)
link = Label(newWindow, text="look out for more clothes", fg="blue", cursor="hand2")
link.place(x=550,y=200)
link.config(font=('Courier',20))
link.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=traditional+dresses+for+women&ref=nb_sb_noss_1"))
path1 = '2017_10$blog_Global Women Cosmetics Market.jpg_17_Oct_2017_071911923.jpg'
img1 = Image.open(path1)
img1 = img1.resize((400,300), Image.ANTIALIAS)
photoImg1= ImageTk.PhotoImage(img1)
panel1 = Label(newWindow, image = photoImg1)
panel1.place(x=100,y=410)
link1 = Label(newWindow, text="look out for more cosmetics", fg="blue", cursor="hand2")
link1.place(x=550,y=550)
link1.config(font=('Courier',20))
link1.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=cosmeticsfor+women&ref=nb_sb_noss_2"))
path2 = '712LwwAdKSL._AC_UL1500_.jpg'
img2 = Image.open(path2)
img2 = img2.resize((400,300), Image.ANTIALIAS)
photoImg2= ImageTk.PhotoImage(img2)
panel2 = Label(newWindow, image = photoImg2)
panel2.place(x=100,y=770)
link2 = Label(newWindow, text="look out for more heels", fg="blue", cursor="hand2")
link2.place(x=550,y=920)
link2.config(font=('Courier',20))
link2.bind("<Button-1>", lambda e: callback("https://www.amazon.com/s?k=heelsfor+women&ref=nb_sb_noss_2"))
kill_button=Button(newWindow,text="Go back",command=newWindow.destroy)
kill_button.config(font=('Courier',20))
kill_button.place(x=1600,y=10)
newWindow.mainloop()
def amazon():
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
cap.release()
cv2.imwrite('gen.jpg',frame)
import test
gender,age=test.suggest('gen.jpg')
al=age.split('-')
ax=int(al[1])
if gender=='Male':
if ax<=10:
child_male('gen.jpg',gender,age)
else:
ad_male('gen.jpg',gender,age)
elif gender=='Female':
if ax<=10:
child_female('gen.jpg',gender,age)
else:
ad_female('gen.jpg',gender,age)
def recognition():
b= geek.load('geekfile1.npy')
l=[]
for i in b:
l.append(i)
def recognize(s,leap):
unknown_picture = face_recognition.load_image_file(s)
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
results = face_recognition.api.face_distance(leap,unknown_face_encoding)
r=list(results)
q=min(r)
if q<=0.45:
return 1
else :
return 2
cond=0
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
while cond==0:
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
cap.release()
img_counter=0
if ret:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5, minSize=(30, 30)
#flags = cv2.CV_HAAR_SCALE_IMAGE
)
if (len(faces)>0):
#ser.write(b'done')
#time.sleep(1.25)
print('done')
print("Found {0} faces".format(len(faces)))
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
#img_counter += 1
qs=recognize(img_name,l)
if qs==1:
label=Label(window,text='Access granted')
a=1
label.config(font=('Courier',64))
label.place(x=600,y=500)
label.after(10000 , lambda: label.destroy())
btn1=Button(window, text = 'Activate system', bd = '5',
command = work)
btn1.config(font=('Courier',35),fg='red')
btn1.place(x=200,y=300)
btn2=Button(window, text='Need any shopping suggestions?',bd=5,
command=amazon)
btn2.config(font=('Courier',35),fg='red')
btn2.place(x=1000,y=300)
btn3=Button(window, text='Exit',bd=5,
command=window.destroy)
btn3.config(font=('Courier',25),fg='blue')
btn3.place(x=1650,y=900)
# Set the position of button on the top of window.
#btn1.place(x=600,y=300)
print('yes')
cond=1
elif qs==2:
label=Label(window,text="Access denied")
#label.insert(INSERT, "ACCESS DENIED")
label.config(font=('Times New Roman',64))
label.place(x=600,y=500)
print('no')
cond=1
# pack is used to show the object in the window
lbl1=Label(window,text='WELCOME')
lbl1.config(bg='grey',fg='black',font=('',70))
lbl1.place(x=700,y=0)
btn = Button(window, text = 'Click here to start engine', bd = '5',
command = recognition)
btn.config(font=('Courier',35),fg='red')
# Set the position of button on the top of window.
btn.place(x=550,y=150)
if a==0:
print('navn')