获取token
import requests
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=填入你的AK&client_secret=填入你的SK'
response = requests.get(host)
if response:
print(response.json())
进行人脸对比(即识别)
import requests
'''
将图片经过base64编码
'''
import base64
def img_to_base(img_name):
with open(img_name,"rb") as f:
base64_data = base64.b64encode(f.read())
return base64_data.decode()
one_img = img_to_base("33.png")
two_img = img_to_base("55.png")
'''
人脸对比
'''
request_url = "https://aip.baidubce.com/rest/2.0/face/v3/match"
params = [{"image": ""+one_img+"", "image_type": "BASE64", "face_type": "LIVE", "quality_control": "LOW"}, {"image": ""+two_img+"", "image_type": "BASE64", "face_type": "IDCARD", "quality_control": "LOW"}]
access_token = '你的access token'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/json'}
response = requests.post(request_url, json=params, headers=headers)
if response:
print(response.json())
print (response.json()['result']['score'])