python人脸识别代码百度ai_python百度AI人脸识别API测试

1、注册账号

2、创建应用

3、得到AK和SK

4、用AK SK获取access_token

可用下面的代码:

#!/usr/bin/python3.5

# encoding:utf-8

import requests

# client_id= 你的AK client_secret =你的SK

host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=4nKZkrripftqdC1Xi&client_secret=oHm8FkEZwYhTussP'

response = requests.get(host)

if response:

print(response.json())

在返回结果里面找access_token,后面的键值就是。

5、测试

网上截图一个小一点的人脸

89ed8105e5fc?utm_campaign=shakespeare

深度linux截图_选择区域_20191126211541.png

6、上传到base64网站转码

http://imgbase64.duoshitong.com/

转好之后删除头部!

89ed8105e5fc?utm_campaign=shakespeare

image.png

先把里面的access_token换成你的。

然后用转换好的代码替换Demo代码

89ed8105e5fc?utm_campaign=shakespeare

image.png

特别注意!

把FACE_TOKEN修改为

89ed8105e5fc?utm_campaign=shakespeare

image.png

89ed8105e5fc?utm_campaign=shakespeare

image.png

8、添加参数

把想获取的都写在这里,用逗号隔开。

89ed8105e5fc?utm_campaign=shakespeare

image.png

参考:

89ed8105e5fc?utm_campaign=shakespeare

image.png

8、附自己修改的完整代码

#!/usr/bin/python3.5

# encoding:utf-8

import requests

'''

人脸检测与属性分析

'''

request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect"

params = "{\"image\":\"iVBORw0KGgoAAAANSUhEUgAAAEIAAAA8CAIAAABdHvsOAAAACX......此处省略......BIWXMAAA7EAAAOxAGVKw4bAAAb6UlEQVRogZ16S6xl2XnW/AAASUVORK5CYII=\",\"image_type\":\"BASE64\",\"face_field\":\"gender,age,beauty\"}"

access_token = '24.bb796f574e5c000.1577364642.282335-17856885'

request_url = request_url + "?access_token=" + access_token

headers = {'content-type': 'application/json'}

response = requests.post(request_url, data=params, headers=headers)

if response:

print (response.json())

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值