🖥
Ruby + GCP Vision API で画像の種類(ラベル)を取得する
準備
gem install google/cloud/vision
コード
require "google/cloud/vision"
image_path = 'gs://cloud-samples-data/vision/label/setagaya.jpeg'
image_annotator = Google::Cloud::Vision.image_annotator
response = image_annotator.label_detection(
image: image_path,
max_results: 10 # optional, defaults to 10
)
response.responses.each do |res|
res.label_annotations.each do |label|
puts label.description
end
end
画像
<img width="654" alt="image" src="https://user-images.githubusercontent.com/13635059/196164817-ebc322a4-f0d5-4795-bcc1-960d2cdd107d.png">
実行
GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json" ruby /path/to/script.rb
結果
Bicycle
Tire
Wheel
Automotive lighting
Infrastructure
Bicycle wheel
Building
Mode of transport
Electricity
Vehicle
参考
- https://www.farend.co.jp/blog/2021/02/cloud-vision-api/
- https://cloud.google.com/vision/docs/labels?hl=ja#vision_label_detection_gcs-python
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2022-10-17
Discussion