1.准备工作
python3
申请百度API https://blog.youkuaiyun.com/student_zz/article/details/91491955
安装python SDK pip install baidu-aip 不会参考https://ai.baidu.com/ai-doc/OCR/Dk3h7yf8m
2.代码
from aip import AipOcr
#import configparser
#在这三个地方填入参数
api_id = '申请的id号'
api_key = '申请的key'
secret_key = '申请的secret key'
client = AipOcr(api_id, api_key, secret_key) #到这里都是固定用法
with open('a.jpg', 'rb') as f:
img = f.read()
text = client.basicGeneral(img)
#通用文字识别方式识别图片内容,一天50000次,像什么高精度版就是basicAccurate,具体参考下方aipocr模块文档
for each in text.get('words_result'):
print(each.get('words')) #返回的是个json,内容在这里面