iT邦幫忙

2021 iThome 鐵人賽

DAY 12
1
自我挑戰組

FRIENDS系列 第 12

Day 12: ML APIs | Google Cloud

Practice

Quest-Integrate with Machine Learning APIs

Lab-Extract, Analyze, and Translate Text from Images with the Cloud ML APIs
  • ID: GSP075
  • Cloud Vision API's text detection method
    • 使用 OCR 從圖片提取文字
  • Translation API
    • 翻譯文字
  • Natural Language API
    • 分析文字
Steps:
1. Create an API Key
  • Cloud Console中,依序點選
    Navigation Menu > APIs & services > Credentials

  • + Create Credentials > 下拉選單選 API key

  • Copy key 後按Close

  • 把Key加入環境變數

export API_KEY=<YOUR_API_KEY>


2. Upload an image to a cloud storage bucket

image: sign.jpg 為偵測目標

  • Search Storage
  • Create Bucket
  • Setting
  • Create
  • 上傳檔案到Cloud Stotage

  • 設定檔案權限為公開


3. Create Vision API request

{
  "requests": [
      {
        "image": {
          "source": {
              "gcsImageUri": "gs://my-bucket-name/sign.jpeg"
          }
        },
        "features": [
          {
            "type": "TEXT_DETECTION",
            "maxResults": 10
          }
        ]
      }
  ]
}

4. Call the Vision API's text detection method

在Cloud shell中,使用curl call the Vision API

curl -s -X POST -H "Content-Type: application/json" --data-binary @ocr-request.json  https://vision.googleapis.com/v1/images:annotate?key=${API_KEY}

可以看到:
[更正-my bucket name為project id]


由於輸出太長,可以輸出到文字檔內

5. Sending text from the image to the Translation API
  • 將圖片擷取的文字交由Translation API進行翻譯
  • 建立translation-request.json
  • 使用上一步驟輸出的文字擋xxxresponse.json

  • Call the Translation API
6. Analyzing the image's text with the Natural Language API

Summary:

上傳圖片到Cloud Storage,
使用Vision API擷取文字,
將擷取出來的文字存到文字檔(.json),
接著使用Translation API可以知道是哪國語言,
並翻譯成target(範例為en:english),
同樣地把翻譯好的結果存在文字檔,
建立Natural Language API 的request JSON檔,
將翻譯好的存檔輸入剛建的request,
再call api得每個word的分析(分類)。


上一篇
Day 11: QwikLabs
下一篇
Day 13: Monitor and Log with Google Cloud Operations Suite: Challenge Lab
系列文
FRIENDS30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
細枝
iT邦新手 4 級 ‧ 2021-09-28 00:42:32

好酷喔!我想知道OCR是怎麼從圖片裡解析文字的

我要留言

立即登入留言