图片文字识别

本文图片文字识别是利用python结合百度AI实现
http://ai.baidu.com/tech/ocr/webimage
下面是具体实现代码:

from aip import AipOcr
APP_ID = 'xxxxxx' #填写自己申请的ID
API_KEY = 'xxxxxxxxxxxxxxxx' #填写自己申请的key
SECRET_KEY = 'xxxxxxxxxxxxxxxxxx' #填写自己申请的DECRET_KEY
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()

if __name__ == '__main__':
img = get_file_content("NB.jpg") #本地图片路径
res = client.basicGeneral(img)
print(res)
#print(type(res))
info = res['words_result']
for i in info:
import re
print(i['words'])
posted @ 2019-04-16 17:20  菜鸟的日记  阅读(898)  评论(0编辑  收藏  举报