一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - python實(shí)現(xiàn)百度OCR圖片識(shí)別過程解析

python實(shí)現(xiàn)百度OCR圖片識(shí)別過程解析

2020-04-17 10:29Maple_feng Python

這篇文章主要介紹了python實(shí)現(xiàn)百度OCR圖片識(shí)別過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了python實(shí)現(xiàn)百度OCR圖片識(shí)別過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

代碼如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import base64
import requests
 
class CodeDemo:
  def __init__(self,AK,SK,code_url,img_path):
    self.AK=AK
    self.SK=SK
    self.code_url=code_url
    self.img_path=img_path
    self.access_token=self.get_access_token()
 
  def get_access_token(self):
    token_host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={ak}&client_secret={sk}'.format(ak=self.AK,sk=self.SK)
    header={'Content-Type': 'application/json; charset=UTF-8'}
    response=requests.post(url=token_host,headers=header)
    content = response.json()
    access_token=content.get("access_token")
    return access_token
 
  def getCode(self):
    header = {
      "Content-Type": "application/x-www-form-urlencoded"
    }
    def read_img():
      with open(self.img_path, "rb")as f:
        return base64.b64encode(f.read()).decode()
 
    image = read_img()
    response=requests.post(url=self.code_url,data={"image":image,"access_token":self.access_token},headers=header)
    return response.json()
 
if __name__ == '__main__':
  AK = "" # 官網(wǎng)獲取的AK
  SK = "" # 官網(wǎng)獲取的SK
  code_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate" # 百度圖片識(shí)別接口地址
  img_path=r"" # 識(shí)別圖片的地址
 
  code_obj=CodeDemo(AK=AK,SK=SK,code_url=code_url,img_path=img_path)
  res=code_obj.getCode()
  code=res.get("words_result")[0].get("words")
  print(res)
  print(code)

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://www.cnblogs.com/angelyan/p/11512450.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 免费在线观看伦理片 | 亚洲人尿尿 | 国产成人精品视频频 | 国产精品一区二区久久 | 天天草b | 爆操俄罗斯美女 | aaa一级特黄 | 日本一二线不卡在线观看 | vomoulei成人舞蹈 | 亚洲国产影院 | 久久毛片基地 | 日本a在线天堂 | 精品精品国产自在久久高清 | 91国内在线国内在线播放 | 91免费永久在线地址 | 亚洲精品国产精品精 | 视频高清在线观看 | 欧美日韩高清完整版在线观看免费 | 成人精品亚洲 | 欧美日韩亚洲国内综合网香蕉 | 深夜成人 | 办公室恋情在线 | 日本人做受全过程视频 | 久久久免费观看 | 午夜dj免费视频观看社区 | 91精品国产91久久久久久麻豆 | 色综合天天综合网国产人 | chinese男gay| 精品国产福利在线 | 国产久草在线 | 国产3p绿奴在线视频 | 欧美日本一区视频免费 | 国产人妖xxxxx免费看 | 国产成人影院一区二区 | 石原莉奈被店长侵犯免费 | 啊啊啊好大在线观看 | 四虎影院在线免费观看视频 | 大胸被c出奶水嗷嗷叫 | 洗濯屋し在线观看 | 国产全部理论片线观看 | 免费超级乱淫播放手机版 |