-
Notifications
You must be signed in to change notification settings - Fork 0
/
faceinfo.py
39 lines (30 loc) · 1.33 KB
/
faceinfo.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
import requests
import json
subscription_key = "YOUR_KEY_HERE"
assert subscription_key
face_api_url = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'
headers = {'Ocp-Apim-Subscription-Key': subscription_key}
params = {
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
}
def get_face_data(image_url):
response = requests.post(face_api_url, params=params,
headers=headers, json={"url": image_url})
face_data_raw = response.json()
return face_data_raw
def organize_data(face_data_raw):
face_data_organized = {
"face_top" : face_data_raw[0]["faceRectangle"]["top"],
"face_left" : face_data_raw[0]["faceRectangle"]["left"],
"face_w" : face_data_raw[0]["faceRectangle"]["width"],
"face_h" : face_data_raw[0]["faceRectangle"]["height"],
"gender" : face_data_raw[0]["faceAttributes"]["gender"],
"age" : face_data_raw[0]["faceAttributes"]["age"],
"glasses" : face_data_raw[0]["faceAttributes"]["glasses"]
}
print(face_data_organized)
return face_data_organized
# organize_data(get_face_data(image_url))
# This returns a dictionary with face details