百度控制台
https://console.bce.baidu.com/ai/#/ai/face/app/detail~appId=2185435
创建一个应用,选择通用文字识别,有免费5W/天,记下appid, appkey, secretkey
下载sdk https://ai.baidu.com/sdk#ocr
安装到python27里
(复制到 C:\Python27\aip-python-sdk-2.2.15 使用 python2 setup.py install注册。)
在线帮助:
https://ai.baidu.com/ai-doc/OCR/7kibizyfm
抄一个官方入门:
#coding:utf-8 from aip import AipOcr """ 你的 APPID AK SK """ APP_ID = '2354xx91' API_KEY = 'ultzPpQDPB3xxxfAwbUo' SECRET_KEY = 'bTIxxxK9uc' path=ur'D:\code-xxxtogui\Snap16.png' """ 读取图片 """ def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() client = AipOcr(APP_ID, API_KEY, SECRET_KEY) image = get_file_content(path) """ 调用通用文字识别, 图片参数为本地图片 """ ret = client.basicGeneral(image); print ret # """ 如果有可选参数 """ # options = {} # options["language_type"] = "CHN_ENG" # options["detect_direction"] = "true" # options["detect_language"] = "true" # options["probability"] = "true" # """ 带参数调用通用文字识别, 图片参数为本地图片 """ # client.basicGeneral(image, options) # url = "https//www.x.com/sample.jpg" # """ 调用通用文字识别, 图片参数为远程url图片 """ # client.basicGeneralUrl(url); # """ 如果有可选参数 """ # options = {} # options["language_type"] = "CHN_ENG" # options["detect_direction"] = "true" # options["detect_language"] = "true" # options["probability"] = "true" # """ 带参数调用通用文字识别, 图片参数为远程url图片 """ # client.basicGeneralUrl(url, options)