Python图片文字识别(百度文字识别API)
程序员文章站
2024-02-27 13:41:27
...
先创建一个百度文字识别的应用获取API
https://ai.baidu.com/进入控制台
创建之后得到API如下:
截个图,准备识别下成绩:
代码:
from aip import AipOcr
APP_ID = 'XXXXXXXXX'
API_KEY ='XXXXXXXXXXXXXXX'
SECRECT_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
client = AipOcr(APP_ID, API_KEY, SECRECT_KEY)
img = open('./gp.png','rb').read()
ret=client.basicGeneral(img)
for item in ret['words_result']:
print(item['words'])
安装百度的AI库
pip install baidu-aip
结果: