A memo when writing your own code based on Official Documents
Install the required packages for the time being. You can do it with requests etc., but projectoxford is easier to write, so I adopted this!
$ pip install projectoxford
After that, prepare a subscription key and an image, and write a program.
face_api.py
import json, requests
from projectoxford import Client
client = Client('<your_subscription_key>')
res = {
"url": "<image_url>",
# or
#'path': '</local/path/to/your_image>',
'analyzesFaceLandmarks': True,
'analyzesAge': True,
'analyzesGender': True,
'analyzesHeadPose': True,
}
result = client.face.detect(res)
print json.dumps(result, indent=4)
#Besides detect, groping, identify, verify,similar etc.
By the way, the result is like this.
$ python face_api.py
[
{
"attributes": {
"gender": "male",
"age": 35,
"headPose": {
"yaw": -7.7,
"roll": -5.7,
"pitch": 0.0
}
},
"faceId": "************************",
"faceRectangle": {
"width": 99,
"top": 80,
"height": 99,
"left": 201
},
"faceLandmarks": {
"underLipTop": {
"y": 160.5,
"x": 250.2
},
"noseTip": {
"y": 129.7,
"x": 247.1
},
"upperLipBottom": {
"y": 149.8,
"x": 249.5
},
"noseLeftAlarTop": {
"y": 124.6,
"x": 240.2
},
"eyebrowLeftOuter": {
"y": 107.8,
"x": 208.7
},
"eyeLeftBottom": {
"y": 112.8,
"x": 226.7
},
"pupilLeft": {
"y": 110.1,
"x": 228.2
},
"upperLipTop": {
"y": 145.1,
"x": 249.1
},
"eyeLeftInner": {
"y": 110.3,
"x": 234.0
},
"eyeRightInner": {
"y": 107.0,
"x": 262.8
},
"eyeLeftTop": {
"y": 108.5,
"x": 227.0
},
"mouthLeft": {
"y": 155.5,
"x": 233.0
},
"noseRightAlarTop": {
"y": 122.7,
"x": 258.3
},
"eyebrowRightInner": {
"y": 101.1,
"x": 253.9
},
"noseLeftAlarOutTip": {
"y": 133.7,
"x": 234.8
},
"noseRightAlarOutTip": {
"y": 130.4,
"x": 263.9
},
"noseRootRight": {
"y": 109.6,
"x": 253.9
},
"eyeLeftOuter": {
"y": 112.4,
"x": 219.9
},
"underLipBottom": {
"y": 166.9,
"x": 251.3
},
"eyeRightTop": {
"y": 102.8,
"x": 269.8
},
"eyeRightOuter": {
"y": 105.1,
"x": 276.1
},
"noseRootLeft": {
"y": 110.9,
"x": 240.6
},
"eyebrowRightOuter": {
"y": 96.1,
"x": 286.1
},
"eyeRightBottom": {
"y": 107.0,
"x": 270.2
},
"eyebrowLeftInner": {
"y": 104.1,
"x": 234.6
},
"mouthRight": {
"y": 150.6,
"x": 272.5
},
"pupilRight": {
"y": 104.4,
"x": 270.5
}
}
}
]
Recommended Posts