Python利用百度AI提取图片中的文字信息
- 安装百度AI : pip install baidu-aip
- 到
https://console.bce.baidu.com/ai/创建文字识别应用,获取APP_ID、API_KEY、SECRET_KEY(可以参考之前的博客:用Python实现人像动漫化)
代码如下
from aip import AipOcr
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
aipOcr=AipOcr(APP_ID, API_KEY, SECRET_KEY)
filePath = "wenzi.png"
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
options = {
'detect_direction': 'true',
'language_type': 'CHN_ENG',
}
result = aipOcr.webImage(get_file_content(filePath),options)
print(result)