百度手写识别
文章目錄
- 問題
- 解決
問題
百度手寫識別解決方案非常簡單,看到喜歡的不得了,十分快速的就能實現文字ocr,無論是圖片還是手寫識別
解決
獲得百度文字識別的鏈接token
搜索百度智能云平臺
點文字識別申請一下
將ak與sk換成在百度智能云上申請的文字識別ak和sk秘鑰字符串
執行后就可以得到鏈接百度智能云的鏈接token字符串
有了這個字符串,將圖片傳送到百度云接口才能被認證通過,這個是鑒權用的
然后就是識別就行了
輸入一個圖片地址,附加鑒權token,得到識別的文字結果
綜合起來就得到一個完整的根據圖片識別文字的函數
# 根據截圖去識別手寫筆跡 # 圖片上傳接口地址 def start_hand(picFilePath):'''手寫文字識別'''def get_token():# client_id 為官網獲取的AK, client_secret 為官網獲取的SKhost = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【ak】&client_secret=【sk】'response = requests.get(host)if response:token = response.json()["access_token"]print(token)return tokenrequest_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting"# 二進制方式打開圖片文件# pic_path = r"C:\Users\Administrator.DESKTOP-KMH7HN6\Desktop\az.jpg"f = open(picFilePath, 'rb')img = base64.b64encode(f.read())params = {"image": img}access_token = get_token()request_url = request_url + "?access_token=" + access_tokenheaders = {'content-type': 'application/x-www-form-urlencoded'}response = requests.post(request_url, data=params, headers=headers)if response:words = ""for i in response.json()["words_result"]:words = words + i["words"] + "\n"return words總結
- 上一篇: opencv+paddle orc 识别
- 下一篇: 原始点,姜治百病理论,害人不浅