import requests
import json
import time
r = requests.post(
url='https://aip.baidubce.com/oauth/2.0/token',
data={
"grant_type": "client_credentials",
"client_id": "s02cZBYwcHcCeadtlI3WGcaW",
"client_secret": "E32mhka4EUKapEC0e6su7QnKLGcLYO93"
})
access_token = r.json()['access_token']
print(access_token)
time.sleep(1)
r2 = requests.post(
url='https://aip.baidubce.com/rest/2.0/ocr/v1/general',
data={
"access_token": access_token,
"url": "http://www.51wendang.com/pic/22e099eef0e5acd550389942/3-810-jpg_6-1080-0-0-1080.jpg"
})
words_result = r2.json()['words_result']
print(words_result)
for result in words_result:
print(result['words'])
方法2:> 先安装 pip install baidu-aip
# encoding:utf-8
import requests
from aip import AipOcr
""" 你的 APPID AK SK """
APP_ID = '16991881'
API_KEY = 's02cZBYwcHcCeadtlI3WGcaW'
SECRET_KEY = 'E32mhka4EUKapEC0e6su7QnKLGcLYO93'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content(r'c:\x4.png')
x=client.basicAccurate(image)
print(x)