Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Created May 5, 2016 19:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devStepsize/f815abf224953a72253cb73fb44e933a to your computer and use it in GitHub Desktop.
Save devStepsize/f815abf224953a72253cb73fb44e933a to your computer and use it in GitHub Desktop.
Detect faces in a local image using the Azure Face API in Python
import json
import urllib
import requests
from pprint import pprint
from os.path import expanduser
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': 'your-api-key',
}
params = urllib.urlencode({
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses',
})
url = 'https://api.projectoxford.ai/face/v1.0/detect?%s' % params
img = open(expanduser('~/pictures/clarifai/burning_basmatty.jpg'), 'rb')
response = requests.post(url, data=img, 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