python呼叫百度通用文字識別介面進行驗證碼識別

2021-09-02 04:42:01 字數 1292 閱讀 2053

aipocr是ocr的python sdk客戶端,為使用ocr的開發人員提供了一系列的互動方法。

from aip import aipocr

api_key = '你的 api key'

secret_key = '你的 secret key'

""" 讀取 """

def get_file_content(filepath):

with open(filepath, 'rb') as fp:

return fp.read()

image = get_file_content('example.jpg')

""" 呼叫通用文字識別, 引數為本地 """

client.basicgeneral(image);

""" 如果有可選引數 """

options = {}

options["language_type"] = "chn_eng"

options["detect_direction"] = "true"

options["detect_language"] = "true"

options["probability"] = "true"

""" 帶引數呼叫通用文字識別, 引數為本地 """

""" 呼叫通用文字識別, 引數為遠端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)

返回示例:

}], 'language': -1}

python 使用百度AI實現OCR文字識別

執行pip install baidu aip from aip import aipocr 更換為自己的註冊資訊 api key secret key fp open img.png rb read 開啟並讀取檔案內容 res client.basicgeneral fp 普通 print res...

python百度文庫文字提取 百度文庫文字爬取

import requests import re import json headers 模擬手機 def get num url response requests.get url,headers headers text print response result re.search r md...

文字識別 百度API呼叫

基於python 2.7 import urllib,urllib2,sys,base64 import ssl import json 獲取access token host 官網獲取的ak client secret 官網獲取的sk request urllib2.request host re...