安装包:
pip install baidu-aip
from aip import AipOcr
from PIL import Image
path='压力报告.png'
###改变图片尺寸
def ResizeImage(path2):
filein = path2
fileout = path2
width = 2000
height = 2500
img = Image.open(filein)
out = img.resize((width, height),Image.ANTIALIAS)
out.save(fileout)
img.close()
###读取图片指标
def get_file_content(filepath):
ResizeImage(path)
APP_ID = '24414511'
API_KEY = 'OUogI3CydVfG54yeK4NwnYQt'
SECRET_KEY = 'swhZn760fvuTAvppUHbCC3CAkRK7Xngw'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
with open(filepath, 'rb') as fp:
image = fp.read()
fp.close()
# 定义参数变量
options = {
# 定义图像方向
'detect-direction': 'true',
'language-type': 'CHN_ENG'
}
result = client.general(image, options)
for word in result['words_result']:
print(word['words'])
get_file_content(path)