Last active
May 5, 2016 19:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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