Created
May 5, 2016 19:07
-
-
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
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 | |
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