Python3-使用百度OCR的API做圖像識別

①登錄百度智能雲賬號,進入管理控制檯,獲取免費模塊
https://login.bce.baidu.com/?account=&redirect=http%3A%2F%2Fconsole.bce.baidu.com%2F
②此處使用【網絡圖片文字識別】,但是有背景瑕疵的驗證碼識別率很低很低,幾乎識別不出來( ‘words_result_num’: 0, ‘words_result’: []),或者識別遺漏。
有時間還是要研究下KNN。
③源碼

import requests
import base64

# 獲取token
access_token=''
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【官網獲取的AK】&client_secret=【官網獲取的SK】'
response = requests.get(host)
if response:
    access_token=response.json()['access_token']

'''
網絡圖片文字識別
'''
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage"
# 二進制方式打開圖片文件
f = open('./VerificationCode/1.png', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
# access_token = '[調用鑑權接口獲取的token]'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章