赞
踩
1、创建应用
百度智能云登录地址:https://login.bce.baidu.com/
2、立即创建
3、得到AppID / API Key / Secret Key
pip install baidu-aip
from aip import AipOcr from os import path APP_ID = "Your AppID" API_KEY = "Your API Key" SECRET_KEY = "Your Secret Key" baidu = AipOcr(APP_ID,API_KEY,SECRET_KEY) father_path = path.dirname(__file__) #得到父级文件夹 content = '' with open('本地图片地址','rb') as f: image = f.read() #得到图片的二进制内容 text = baidu.basicAccurate(image) #调用百度的接口识别图片文字内容 result = text['words_result'] #获取返回内容的列表 for i in result: content += i['words'] + '\n' # 将文件内容写入txt文件 fp = open('%s\识别内容.txt'%father_path,'a+',encoding='utf-8') print(content,file=fp) fp.close
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。