準備
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
画像
実行
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オープンチャットもご利用ください。