import base64 import urllib3,base64 import json from urllib.parse import urlencode access_token='your' http=urllib3.PoolManager() url='https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token='+access_token f = open('image.png','rb') #参数image:图像base64编码 img = base64.b64encode(f.read()) params={'image':img} #对base64数据进行urlencode处理 params=urlencode(params) request=http.request('POST', url, body=params, headers={'Content-Type':'application/x-www-form-urlencoded'}) #对返回的byte字节进行处理。Python3输出位串,而不是可读的字符串,需要进行转换 result = str(request.data,'utf-8') #返回参数json序列化处理 res = json.loads(result) print(res)
有图片可以打开图片识别,那只有图片的url代码应该怎么改才可用呢?
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
谢谢,我试试
没用过,不太清楚
import requests
from aip import AipOcr
image = requests.get('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545297615249&di=417de420f364ff1d5191a24599f08783&imgtype=0&src=http%3A%2F%2Fimg238.ph.126.net%2Fqd0R2smfhpib4ag_VhyIhQ%3D%3D%2F1421730107367067801.jpg').content
APP_ID =
API_KEY =
SECRET_KEY=
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
res = client.basicAccurate(image)
if 'words_result' in res.keys():
for item in res['words_result']:
print(item['words'])
这个涉及到文字识别,调用python的SDK?