成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Go車(chē)牌識(shí)別(網(wǎng)絡(luò)圖片|本地圖片)

Go  車(chē)牌識(shí)別 (網(wǎng)絡(luò)圖片| 本地圖片)

在成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)中從網(wǎng)站色彩、結(jié)構(gòu)布局、欄目設(shè)置、關(guān)鍵詞群組等細(xì)微處著手,突出企業(yè)的產(chǎn)品/服務(wù)/品牌,幫助企業(yè)鎖定精準(zhǔn)用戶,提高在線咨詢和轉(zhuǎn)化,使成都網(wǎng)站營(yíng)銷(xiāo)成為有效果、有回報(bào)的無(wú)錫營(yíng)銷(xiāo)推廣。創(chuàng)新互聯(lián)建站專業(yè)成都網(wǎng)站建設(shè)10年了,客戶滿意度97.8%,歡迎成都創(chuàng)新互聯(lián)客戶聯(lián)系。

先注冊(cè)一個(gè)百度云賬號(hào),然后選擇 人工智能 文字識(shí)別,創(chuàng)建一個(gè)應(yīng)用。獲取appkey secret 。

網(wǎng)絡(luò)圖片

package main

import (
   "encoding/base64"
   "encoding/json"
   "io/ioutil"
   "log"
   "net/http"
   "net/url"
)

func main() {
   handler := PlateHandler{}

   appKey := "11111"
   secret := "11111111z"
   accessToken := handler.GetAccessToken(appKey, secret)
   log.Println("獲取到的accessToken:",accessToken)

   pictureUrl := "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2181674788,2215933125&fm=26&gp=0.jpg"
   plate,err:=handler.GetPlate(pictureUrl,accessToken)
   if err!=nil{
      log.Fatal("獲取車(chē)牌失敗",err)
   }
   log.Println("獲取到的車(chē)牌:",plate)
}

type accessTokenInfo struct {
   AccessToken string `json:"access_token"`
   ExpiresIn   int64  `json:"expires_in""`
}

type WordResult struct {
   Number string `json:"number"`
}
type Data struct {
   WordsResult WordResult `json:"words_result"`
}
type PlateHandler struct {
}

func (handler *PlateHandler) GetAccessToken(appKey string, appSecret string) (accessToken string) {
   url := "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="+appKey+"&client_secret="+appSecret

   response, err := http.Get(url)
   if err != nil {
      log.Fatal(err)
      return ""
   }
   data, err := ioutil.ReadAll(response.Body)
   if err != nil {
      log.Fatal(err)
      return ""
   }
   info := accessTokenInfo{}
   json.Unmarshal(data, &info)
   log.Print("請(qǐng)求accessToken返回的數(shù)據(jù):", string(data))
   return info.AccessToken
}

func (handler *PlateHandler) GetPlate(picture_url string,accessToken string) (plate string, err error) {
   rsp, err := http.Get(picture_url)
   if err != nil {
      log.Fatal(err)
      return "", err
   }
   image, _ := ioutil.ReadAll(rsp.Body)
   image_value, err2 := url.Parse(base64.StdEncoding.EncodeToString(image))
   if err2 != nil {
      log.Fatal(err)
      return "", err
   }
   to_url := "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate?access_token="+accessToken
   values := url.Values{}
   values.Add("image", image_value.EscapedPath())
   values.Add("multi_detect", "false")
   rsp2, err := http.PostForm(to_url, values)
   defer rsp2.Body.Close()
   if err != nil {
      log.Fatal(err)
      return "", err
   }
   data, err := ioutil.ReadAll(rsp2.Body)
   if err != nil {
      log.Fatal(err)

      return "", err
   }
   log.Println("請(qǐng)求車(chē)牌返回的數(shù)據(jù):",string(data))
   m := Data{}
   err = json.Unmarshal(data, &m)
   if err != nil {
      log.Fatal(err)
      return "", err
   }
   log.Println(m)
   return m.WordsResult.Number, nil
}

本地圖片

package main

import (
   "encoding/base64"
   "encoding/json"
   "io/ioutil"
   "log"
   "net/http"
   "net/url"
   "os"
)

func main() {
   handler := PlateHandler{}

   appKey := "111111111"
   secret := "111111111"
   accessToken := handler.GetAccessToken(appKey, secret)
   log.Println("獲取到的accessToken:",accessToken)

   pictureUrl := "day02/img/1.png"    // 路徑,從根開(kāi)始寫(xiě)
   plate,err:=handler.GetPlate(pictureUrl,accessToken)
   if err!=nil{
      log.Fatal("獲取車(chē)牌失敗",err)
   }
   log.Println("獲取到的車(chē)牌:",plate)
}

type accessTokenInfo struct {
   AccessToken string `json:"access_token"`
   ExpiresIn   int64  `json:"expires_in""`
}

type WordResult struct {
   Number string `json:"number"`
}
type Data struct {
   WordsResult WordResult `json:"words_result"`
}
type PlateHandler struct {
}

func (handler *PlateHandler) GetAccessToken(appKey string, appSecret string) (accessToken string) {
   url := "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="+appKey+"&client_secret="+appSecret

   response, err := http.Get(url)
   if err != nil {
      log.Fatal(err)
      return ""
   }
   data, err := ioutil.ReadAll(response.Body)
   if err != nil {
      log.Fatal(err)
      return ""
   }
   info := accessTokenInfo{}
   json.Unmarshal(data, &info)
   log.Print("請(qǐng)求accessToken返回的數(shù)據(jù):", string(data))
   return info.AccessToken
}

func (handler *PlateHandler) GetPlate(picture_url string,accessToken string) (plate string, err error) {

   ff, _ := os.Open(picture_url)
   sourcebuffer := make([]byte, 50000000000)
   n, _ := ff.Read(sourcebuffer)
   //base64壓縮
   sourcestring := base64.StdEncoding.EncodeToString(sourcebuffer[:n])

   to_url := "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate?access_token="+accessToken

   values := url.Values{}
   values.Add("image", sourcestring)
   values.Add("multi_detect", "false")
   rsp2, err := http.PostForm(to_url, values)
   defer rsp2.Body.Close()
   if err != nil {
      log.Fatal(err)
      return "", err
   }
   data, err := ioutil.ReadAll(rsp2.Body)
   if err != nil {
      log.Fatal(err)

      return "", err
   }
   log.Println("請(qǐng)求車(chē)牌返回的數(shù)據(jù):",string(data))
   m := Data{}
   err = json.Unmarshal(data, &m)
   if err != nil {
      log.Fatal(err)
      return "", err
   }
   log.Println(m)
   return m.WordsResult.Number, nil
}

結(jié)果

2019/12/25 11:48:34 請(qǐng)求車(chē)牌返回的數(shù)據(jù): {"log_id": 8926648569804002425, "words_result": {"color": "blue", "number": "豫A99999", "probability": [0.9014493227005005, 0.9014158248901367, 0.900929868221283, 0.9012478590011597, 0.901341438293457, 0.9010871052742004, 0.9010393619537354], "vertexes_location": [{"y": 181, "x": 241}, {"y": 173, "x": 439}, {"y": 229, "x": 442}, {"y": 236, "x": 244}]}}
2019/12/25 11:48:34 {{豫A99999}}
2019/12/25 11:48:34 獲取到的車(chē)牌: 豫A99999

新聞標(biāo)題:Go車(chē)牌識(shí)別(網(wǎng)絡(luò)圖片|本地圖片)
轉(zhuǎn)載來(lái)于:http://jinyejixie.com/article36/pggcpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)網(wǎng)站維護(hù)、外貿(mào)建站、ChatGPT、網(wǎng)站設(shè)計(jì)公司軟件開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)
凤冈县| 西昌市| 青冈县| 团风县| 丹寨县| 贡嘎县| 镇安县| 荆门市| 泰顺县| 原平市| 唐海县| 江安县| 高要市| 安乡县| 根河市| 新蔡县| 北票市| 贵州省| 鄱阳县| 旺苍县| 乌兰察布市| 赤水市| 黄山市| 高安市| 康马县| 泾阳县| 贵南县| 嘉义县| 兰西县| 句容市| 十堰市| 隆昌县| 甘德县| 连山| 乡宁县| 普格县| 鄂州市| 项城市| 新安县| 安庆市| 积石山|