调用百度API,识别pdf图片

python -V 3.7

import requests
import base64
import urllib3
urllib3.disable_warnings()

# """ 你的 APPID AK SK """
APP_ID = "xxxxxxx"
API_KEY = "xxxxxxxxxxxxx"
SECRET_KEY = "xxxxxxxxxxxxxxxx"
#
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【你的API_KEY】&client_secret=【你的SECRET_KEY】'
response = requests.get(host,verify=False)

if response:
    token = response.json()['access_token']

# print(token)


request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general"
# 二进制方式打开图片文件
f = open('./1.png', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = token
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    json_1 = response.json()
# print(json_1.keys())  # dict_keys(['log_id', 'words_result_num', 'words_result'])
# print(json_1['words_result_num'])
# print(json_1)
jsonArray=json_1['words_result']
# print(jsonArray)


for i in range (len(jsonArray)):
	# print(jsonArray[i])
    words=jsonArray[i]['words']
    print(words)

下面就是1.png
在这里插入图片描述
程序运行结果:

合格证
Calvin Klein Jeans
209767-05
等圾:合格品
品牌: CK JEANS
晶名:牛仔外套
产地:土耳其制
产号:J209767
号型:160/76AS
执行标准:F/810052017
安全技术卖别:符台GB1B401C英
直接制发产
料成分及洗涤方法详见内标
水洗产品
076791140
检验员:Jm2
s83
¥2490.00
代理商:碘卫齐尚业|上海限公司
地址上海市静安区安脑55号忆2[Finished in 1.4s]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白蒋博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值