1. 程式人生 > >使用百度ocr接口識別驗證碼

使用百度ocr接口識別驗證碼

highlight 驗證碼 created name basic create turn words 地圖

#!/usr/bin/env python
#created by Baird

from aip import AipOcr

def GetCaptchaV(filename):
    APP_ID = ‘1X4X8X4X‘
    API_KEY = ‘YaVcqamctoYqRHNGAqwVbn97UO‘
    SECRET_KEY = ‘C1926rIqGstqPHTUFa6sz481fjDua2pv‘

    client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

    """ 讀取圖片 """
    def get_file_content(filePath):
        with open(filePath, ‘rb‘) as fp:
            return fp.read()

    image = get_file_content(filename)

    """ 調用通用文字識別, 圖片參數為本地圖片 """
    ret = client.basicGeneral(image)

    code = ret["words_result"][0]["words"]
    print("識別驗證碼成功===》",code)
    return code

  

使用百度ocr接口識別驗證碼