Let's use the python requests library, and a free trial of Microsoft's computer vision API to identify celebrities in photos.
This short tutorial is aimed at showing developers how accessible and user friendly cognitive services can be. This tutorial is taken largely inpart from Microsoft's Cognitive Services documentation, it can be found here.
To start, your going to need a free subscription key from here.
First, we need to import the requests library
import requests
Then we need the keys, and some basic URL's. We're going to use these values from the computer vision API documentation.
#subscription key
key = "your key here"
#Base endpoint and special celebrity endpoint
vision_base_url = "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/"
celebrity_analyze_url = vision_base_url + "models/celebrities/analyze"
Next we need an image of a celebrity.I'll start with the king of pop.
Micheal Jackson
image_url = "http://images2.fanpop.com/image/photos/10700000/Close-Up-Large-Photo-michael-jackson-10731676-1267-1333.jpg"
We're going to need some basic HTTP variables set up. These values are standard and have been taken from the documentation.
h = {'Ocp-Apim-Subscription-Key':key}
p = {'visualFeatures': 'Categories,Description,Color'}
d = {'url':image_url}
We finally send the request to the service.
response = requests.post(celebrity_analyze_url,headers=h,params=p,json=d)
analysis = response.json()
Let's look at our results:
result = analysis["result"]["celebrities"][0]["name"]
print(result)
Micheal Jackson
Comment which celebrities the service can and can't recognize.
I've got the first one, this service can't recognize Prince...
Top comments (0)