0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ruby + GCP Vision API で画像の種類(ラベル)を取得する

Posted at

準備

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

画像

image

実行

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

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?