先参考:百度ocr识别API文档 ;上面有详细步骤,使用百度账号登录,首次创建新的应用,创建后的应用界面如下:
1.Python环境:Python3.6;
2.安装Python三方库:baidu-aip
3.代码实现,如下实现的是高精度实现方法:
from aip import AipOcr def baiduOCR(picfile): # picfile:图片文件名 # 百度提供 """ 你的 APPID AK SK """ APP_ID = '*******' # 应用的appid API_KEY = '*******' # 应用的appkey SECRET_KEY = '*******' # 应用的secretkey client = AipOcr(APP_ID, API_KEY, SECRET_KEY) i = open(picfile, 'rb') img = i.read() """ 调用通用文字识别(高精度版) """ message = client.basicAccurate(img) i.close() # 输出文本内容 for text in message.get('words_result'): # 识别的内容 print(text) print(text.get('words')) if __name__ == '__main__': baiduOCR('C:/test.png')