利用百度API,识别图片的文字
from aip import AipOcr
#输入百度智能云的APP的Id/Key等
config = {
'appId': 'XXX',
'apiKey': 'XXX',
'secretKey': 'XXX'
}
client = AipOcr(**config)
def get_file_content(file):
with open(file, 'rb') as f:
return f.read()
# a = get_file_content('cat.jpg')
# print(a)
def img_to_str(image_path):
image = get_file_content(image_path)
result = client.handwriting(image)
print(result)
if 'words_result' in result:
return '\n'.join([w['words'] for w in result['words_result']])
b = img_to_str('GB_7142_页面_06.jpg')
print(b)