python名人问题_Python名人识别器

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 keykey = "your key here"

#Base endpoint and special celebrity endpointvision_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...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值