zoukankan      html  css  js  c++  java
  • python27+百度文字识别api

    百度控制台

    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:Python27aip-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-xxxtoguiSnap16.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)
  • 相关阅读:
    新式类、经典类与多继承
    实现抽象类之方式二
    实现抽象类之方式一
    re模块
    28个高频Linux命令
    Git使用教程
    编程语言介绍
    编码
    进制
    操作系统简史
  • 原文地址:https://www.cnblogs.com/yansc/p/14281275.html
Copyright © 2011-2022 走看看