百度智能云账户注册:https://console.bce.baidu.com/ai/#/ai/ocr/app/list
获取appid、api_key、secret_key
python">from aip import AipOcr
import osconfig = {'appid': '116122887','api_key': 'DAQnt...','secret_key': '5S0Kpyh....'
}# 初始化 AipOcr 客户端
client = AipOcr(config['appid'], config['api_key'], config['secret_key'])# 获取文件内容
def get_file_content(filePath):with open(filePath, 'rb') as fp:return fp.read() # 识别图像的文字
def get_text(filePath):image = get_file_content(filePath)result = client.handwriting(image)# return result['words_result']if 'words_result' in result:return '\n'.join([w['words'] for w in result['words_result']])# 调用识别函数
res = get_text(r'D:\mini\ocr.jpg')
print(res)