python 百度ai尝试

  • 看到实验室的小可爱在玩,所以索性也就试了一下
  • 这个只是其中的识别图片中文字的api调用测试
import requests;
import base64;
askurl =  'https://aip.baidubce.com/oauth/2.0/token'
data={
    'grant_type':'client_credentials',
    'client_id':'xxx',#api key
    'client_secret':'xxx'#serect key
}
request = requests.post(askurl,data=data)
assess_token=eval(request.text)['access_token']

url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/webimage?access_token='+assess_token
headers={
    'Content-Type':'application/x-www-form-urlencoded',
}

f = open('1.png','rb')
img = base64.b64encode(f.read())
#print(img.decode())
params={
    'image':img
}
#params = urllib.urlencode(params)
request = requests.post(url,data=params,headers=headers)
if (request.content):
    print(request.content.decode())

  • 所用图片:
    python 百度ai尝试_第1张图片
  • 结果

python 百度ai尝试_第2张图片

你可能感兴趣的:(python)