LoginSignup
2
3

More than 5 years have passed since last update.

Cloud Vision APIで画像解析

Last updated at Posted at 2018-09-11

Cloud Vision APIで画像解析

Cloud Vision APIとは

  • Google Cloud Platform(GCP)が提供する機械学習サービス
  • Googleの持つ画像に関する機械学習モデルを使い、対象となる画像から以下の情報を取得することができます。
    • 猫やヨットなど、画像に含まれている物体の検知  - 画像内に含まれている文章やロゴの取得
    • 人物の顔認識やその表情が示す感情に関する情報の取得
    • コンテンツが暴力的など不適切な要素を持つかの判定

VisionAPIイメージ.png

今回は↓をやってみた

ウェブの力を活用(ウェブ検出)

  • Googleの画像検索を活用し、著名人やロゴ、ニュース イベントなどの時事的なエンティティを検出
  • この機能と類似画像検索を組み合わせてウェブ上で類似している画像を検索

実行手順

Vision APIを有効にする

サービスアカウントを使用して認証を設定する

サービスアカウント作成(Role不要)
アプリケーションのデフォルト認証情報設定

export GOOGLE_APPLICATION_CREDENTIALS="/home/xxxxx/development-visionapi.json"

サービスアカウントのアクティベート

gcloud auth activate-service-account development-visionapi@xxxx.iam.gserviceaccount.com --key-file=/home/xxxxx/development-visionapi.json --project=xxxxx

環境設定(クライアントライブラリ設定)

git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
virtualenv env
source env/bin/activate
cd /home/xxxxx/python-docs-samples/vision/cloud-client/detect
pip install -r requirements.txt

画像の準備

GCSバケット作成と権限設定、ファイルアップロードを行う

今回この画像を使ってウェブ検出してみた

Footballchannelよりph_messi.jpg
あの人でしょ・・・?

検出実行

$ python detect.py web-uri gs://xxxx/ph_messi.jpg

検出結果

以下のような結果が返ってくる

Best guess label:
(もっともあてはまるラベル)
10 Pages with matching images found:
(一致するページのリスト)
10 Web entities found:
(ウェブ エンティティとその説明およびスコアのリスト)
8 visually similar images found:
(類似した画像)

今回(2018/8/28実行)だと以下の結果でした

Best guess label: messi double moskau

"メッシ" "ダブル(そっくりさん)" "モスクワ"

10 Pages with matching images found:
        Page url   : https://www.gettyimages.ca/detail/news-photo/iranian-lionel-messi-lookalike-university-student-reza-news-photo/681904592
略)

一致するページとしては以下などがあがってきました
こちらでした

10 Web entities found:
        Score      : 13.345499992370605
        Description: Lionel Messi
        Score      : 1.163580060005188
        Description: 2018 World Cup
        Score      : 1.0410000085830688
        Description: Argentina national football team
        Score      : 0.7657500505447388
        Description: Great children’s party
        Score      : 0.7534500360488892
        Description: Iran

エンティティは
"Lionel Messi"
"2018 World Cup"
"Argentina national football team"
"Great children’s party"
"Iran"

8 visually similar images found:
        Image url    : https://www.welt.de/img/sport/mobile177463464/6632503087-ci102l-w1024/The-Iranian-
Messi-lookalike.jpg
略)

似通った画像として
"The-Iranian-Messi-lookalike.jpg"

つまりメッシのそっくりさんだよという結果となりました
もしかしたらニュースになった直後だとメッシだよという答えが多かったりするのかも
そう考えるとGoogleの画像における機械学習はすごいですね!

参照

2
3
1

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
2
3