–
from aip import AipOcr
import chardet
"""定义常量"""
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
"""初始化对象"""
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('image.png')
"""调用通用文字识别接口, 识别本地图像"""
result = client.basicGeneral(image)
print(result)
# 打印每行文字
for item in result['words_result']:
print(item['words'])
# 将每行文字拼接成一个整体
string_text = ""
for item in result['words_result']:
string_text += item['words']
print('string_text:', string_text)
–
–
发表回复