python百度orc识别

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)

 

 

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注