-
Notifications
You must be signed in to change notification settings - Fork 2
/
FaceRekog_lambda_incomplete
144 lines (117 loc) · 3.48 KB
/
FaceRekog_lambda_incomplete
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
import boto3
def detFace(img, bkt, rekog):
responsex = rekog.detect_faces(
Image={
'S3Object': {
'Bucket': bkt,
'Name': img
}
},
Attributes=[
'ALL',
]
)
out3 = []
for i in responsex['FaceDetails']:
out3.append(i)
print(out3)
return out3
def getEmot(details):
for match in details:
print('The Person infront of you is ')
print(match['Emotions'][0]['Type'], '\n')
def getFaceDet(details):
for match in details:
print('You are seeing a ', match['Gender']['Value'])
print('The age ranges between ', match['AgeRange']['Low'], ' and ', match['AgeRange']['High'])
if (match['Gender']['Value'] == 'Male'):
if (match['Beard']['Value']):
print ("with beard")
if (match['Mustache']['Value']):
print ("with Mustache")
def indexFace(img, bkt, cID, rekog):
response = rekog.index_faces(
CollectionId= cID,
Image={
'S3Object': {
'Bucket': bkt,
'Name': img
}
},
DetectionAttributes=[
'ALL',
]
)
out = []
for i in response['FaceRecords']:
out.append(i['Face']['FaceId'])
#responses = rekog.search_faces(
# CollectionId='omg',
# FaceId=phid,
#)
print(out)
return out
def searchFace(bkt, cID, index, rekog):
flag = 1
for i in index:
responses = rekog.search_faces(
CollectionId= cID,
FaceId= i,
)
for match in responses['FaceMatches']:
if(match['Similarity'] > 70):
flag = 0;
if ('ExternalImageId' in match['Face']):
print(match['Face']['ExternalImageId'], '\n')
return flag
def ask(image, bkt, iID, cID, det, client, rekog):
getFaceDet(det)
doyou = input("Do you want to add this person? ")
type(doyou)
if(doyou == 'yes'):
iID = input("Say the person's name ")
type(iID)
print (iID , '\n')
# a solo pic
response1 = rekog.index_faces(
CollectionId=cID,
Image={
'S3Object': {
'Bucket': bkt,
'Name': image
}
},
ExternalImageId= iID,
DetectionAttributes=[
'ALL',
]
)
print(response1, '\n')
else:
response2 = client.delete_object(
Bucket= bkt,
Key= image
)
def lambda_handler(event, context):
# TODO implement
# client = boto3.client('s3')
# client.upload_file('dody1.jpg', 'ai5', 'dody1.jpg')
# rekog = boto3.client('rekognition')
Input = 'Amor.jpg'
client = boto3.client('s3')
#client.upload_file(Input, 'abdelshahied', Input)
rekog = boto3.client('rekognition')
det = detFace(Input, 'abdelshahied', rekog)
indecies = indexFace(Input, 'abdelshahied', 'omg', rekog)
first = searchFace('abdelshahied', 'omg', indecies, rekog)
iID = []
cID = []
if (first):
ask(Input, 'abdelshahied', iID, cID, det, client, rekog)
else:
response2 = client.delete_object(
Bucket= 'abdelshahied',
Key= Input
)
# Input = input("image searching for ")
#return 'Hello from Lambda'