Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Last active May 5, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devStepsize/57e863679776b9ab896ab377d1179599 to your computer and use it in GitHub Desktop.
Save devStepsize/57e863679776b9ab896ab377d1179599 to your computer and use it in GitHub Desktop.
Detect faces in a public image using the Azure Face API in Python
import json
import urllib
import requests
from pprint import pprint
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'your-api-key',
}
params = urllib.urlencode({
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses',
})
body = {
'url': 'http://i.imgur.com/jJWlcnR.jpg'
}
url = 'https://api.projectoxford.ai/face/v1.0/detect?%s' % params
response = requests.post(url, data=json.dumps(body), headers=headers)
pprint(response.json())
if response.status_code != 200:
raise ValueError(
'Request to Azure returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment