日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python基于百度API的ORC文字识别

發布時間:2023/12/2 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python基于百度API的ORC文字识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python基于百度API的ORC文字識別

  • python基于百度API的ORC文字識別

python基于百度API的ORC文字識別

# encoding:utf-8import requests import base64# 文字識別模塊 高精度:https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic 普通:general_basic request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" # 二進制方式打開圖片 f = open('C:\\Users\\bill_love_sea\\Desktop\\python\\20200617140056.jpg', 'rb') img = base64.b64encode(f.read()) # 獲取API相關的參數:access_token,headers,data 等 params = {"image": img} access_token = '24.253c31adc2d26d728940cf62c65013c0.2592000.1597372330.282335-21365498' request_url = request_url + '?access_token=' + access_token headers = {'content_type': 'application/x-www-form-urlencoded'} # 以POST方式進行請求 response = requests.post(request_url, data=params, headers=headers) # 輸出響應結果 if response:a = dict(response.json())for words in a['words_result']:print(words['words'])

調取API的基本過程百度云的相關文檔都有,可以自行參考,其中‘access_token’參數的獲取如下:

# encoding:utf-8 import requests # client_id 為官網獲取的AK, client_secret 為官網獲取的SK AK = 'ysLHhFMBBGOq6wTZeoS6W6aX' SK = '9wioD22eKhFoyfv8rcdO01lzBunUq4S6' 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:print(response.json()['access_token'])

總結

以上是生活随笔為你收集整理的python基于百度API的ORC文字识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。