-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_recognition.py
132 lines (61 loc) · 2.28 KB
/
face_recognition.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
import requests
import base64
import json
api_credentials={
"Content-Type":"application/json",
"app_id":"75f5edf9",
"app_key":"ba0eadb825eddeb58d420e08bad09300"
}
url="https://api.kairos.com/"
def _extract_base64_contents(file):
with open(file, 'rb') as fp:
image = base64.b64encode(fp.read()).decode('ascii')
return image
def post(image_link,identifier):
payload={
"image":_extract_base64_contents(image_link),
"subject_id":identifier,
"gallery_name":"gallery"
}
response=requests.post(url+"enroll",json=payload,headers=api_credentials).json()
print "\n Detected attributes of New user\n"
print ("Gender : ",response["images"][0]["attributes"]["gender"]["type"])
print ("Age : ",response["images"][0]["attributes"]["age"])
#print parsed.dumps(parsed,indent=4,sort_keys=True)
def recognize(image_link):
payload={
"image":_extract_base64_contents(image_link),
"gallery_name":"gallery"
}
response=requests.post(url+"recognize",json=payload,headers=api_credentials)
#with open("")
gallery_response=response.json()
# print gallery_response
if 'Errors' in gallery_response:
return -2
# print gallery_response
if gallery_response["images"][0]["transaction"]["status"]=="success":
print "Image Detected with : ",gallery_response["images"][0]["transaction"]["confidence"]*100,"% Resemblance Factor"
return gallery_response["images"][0]["transaction"]["subject_id"]
print 'New User Found'
return -1
def view_gallery():
payload={
"gallery_name": "gallery"
}
response=requests.post(url+"gallery/view",json=payload,headers=api_credentials)
print(response.json())
def delete_user(identifier):
payload={
"subject_id":identifier,
"gallery_name":"gallery"
}
response=requests.post(url+"gallery/remove_subject",json=payload,headers=api_credentials)
print(response.json())
#post("http://media.kairos.com/kairos-elizabeth.jpg","1")
#post("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcT7qBsj6rkafzGP6rTmZRpUYinKVI4HU8VXZjxG1TsthEoJmocl8UG6KKLT","2")
#print recognize("Crazy.png")
#print recognize("pp.jpg")
#post("Img.png","pawan")
#view_gallery()
#delete_user("5")