基於python的百度雲OCR 2

2021-09-26 02:48:51 字數 1208 閱讀 9060

import base64

import requests

class ocr(object):

# client_id 為官網獲取的ak, client_secret 為官網獲取的sk

client_id = "your-key"

client_secret = "your-secret-key"

def get_token(self):

"""獲取 access_token"""

host = ''

# 請求頭

# 請求引數

params =

# get 請求

response = requests.get(host, headers=headers, params=params)

# 獲取 json 內容

content = response.json()

# 獲取 access_token

access_token = content["access_token"]

return access_token

def encode_img(self, img_path):

"""對進行編碼"""

with open(img_path, "rb") as f:

img_content = f.read()

# 對進行 base64 編碼

img_content = base64.b64encode(img_content)

return img_content

def img_to_str(self, img_path):

"""對文字進行識別"""

access_token = self.get_token()

# 請求 url

url = "" + access_token

# post 請求頭

# post 引數

data =

# post 請求

response = requests.post(url, headers=headers, data=data)

return response.json()

if __name__ == '__main__':

ocr = ocr()

print(ocr.img_to_str("your image's path"))

百度OCR識別初體驗

將sdk放入要載入專案的根目錄 2.在專案根目錄下執行npm install sdk檔名 3.具體引用方法檢視sdk中的package.json中的配置 專案目錄結構 idcard.png 身份證 新建aipocrclient ocrclient是optical character recognit...

百度AI介面OCR識別

要有賬號,這個是要花錢的!通過前端傳來的 的路徑,返回出卡號和銀行名稱 先通過這個類獲得 token 獲取api訪問token 該token有一定的有效期,需要自行管理,當失效時需重新獲取.param param return assess token 示例 24.460da4889caad24cc...

百度雲推送

主要功能是 推送通知 推送訊息 推送富 特點 1 增強使用者粘性 保持與使用者的溝通,提高使用者活躍率。2 節約成本 省點 省流量。3 穩定 可靠。應用場景 單播訊息推送 1 向特定的終端推送訊息 通過客戶端api,先獲取終端的channel id,再向channel id推送訊息。2 向可定的使用...