大赵传奇

援引事类,扬搉古今,举要删芜,言辩而理切--QQ276605216

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

百度控制台

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)

 

posted on 2021-01-15 11:38  赵长青  阅读(120)  评论(0编辑  收藏  举报