LoginSignup
0
0

More than 3 years have passed since last update.

Android で CloudVision API を使ってウェブ検出する

Posted at

Android で CloudVision API を使ってラベル検出する
の続きです。

前回の記事では、ラベル検出を行った。
今回は、ウェブ検出を行う。

下記を参考にした。

docs : ウェブ検出のチュートリアル

参考 : Android : Google Cloud Vision APIを用いてWEB_DETECTIONする

リクエストを作成する

基本的な処理は、ラベル検出と同じです。

違いは、機能のタイプにウェブ検出を指定すること。

docs : Feature 機能

                Feature feature = new Feature();
// ウェブ検出を指定する
                feature.setType("WEB_DETECTION");

ウェブ検出のレスポンス

ラベル検出では、取得できるアノテーションはラベルだけでした。

ウェブ検出では、下記のアノテーションが取得できる。

  • ウェブから取得したラベル
  • 一致する画像のあるサイト URL
  • リクエスト中の画像に部分一致または完全一致するウェブ画像を参照する URL
  • 視覚的に類似している画像を参照する URL

WebDetection

ウェブ検出のレスポンスのクラス

documentation : WebDetection

        AnnotateImageResponse response

        WebDetection webDetection = response.getWebDetection();

// 最も適切に推測したラベル
        List<WebLabel>  bestGuessLabels = webDetection.getBestGuessLabels();
// ウェブから取得したラベル
        List<WebEntity> webEntities = webDetection.getWebEntities();
// 一致する画像のあるサイト
        List<WebPage>   pagesWithMatchingImages = webDetection.getPagesWithMatchingImages();
// 完全一致する画像
        List<WebImage>   fullMatchingImages = webDetection.getFullMatchingImages();
// 部分一致する画像
        List<WebImage>   partialMatchingImages = webDetection.getPartialMatchingImages();
// 類似している画像
        List<WebImage> visuallySimilarImages = webDetection.getVisuallySimilarImages();

WebLabel

ウェブラベルのメタデータ
ラベルが取得できる

documentation : WebLabel

WebEntity

ウェブエンティティのメタデータ
ラベルとスコアが取得できる

documentation : WebEntity

WebPage

ウェブページのメタデータ
- 一致する画像のあるサイトのURLと、
- 一致する画像のURLが取得できる

documentation : WebPage

WebImage

オンライン画像のメタデータ
- 一致する画像のURLが取得できる

documentation : WebImage

レスポンスの処理

  • 一致する画像のあるサイトのURLから ウェブブラウザアプリでそのサイトを表示する。
  • 一致する画像のURLから その画像を表示する。

実行例

スクリーンショット
cloud_vision2_image_list.png

テキスト

I found these things:
bestGuessLabels:
google cloud vision api label direction
webEntities:
Google Cloud Platform: 0.825
Application programming interface: 0.703
American Cocker Spaniel: 0.569
Cloud computing: 0.567
Google: 0.526
Application software: 0.460
Google APIs: 0.391
Library: 0.378

pagesWithMatchingImages: 10
fullMatchingImages: 4
partialMatchingImages: 3
visuallySimilarImages: 0

レスポンス

写真に写っているのは、アメリカンコッカースパニエル。
推測したラベルは、
google cloud vision api label direction 。
一致する画像のあるサイトは、
https://cloud.google.com/vision/docs/detecting-labels
一致する画像は、
https://cloud.google.com/vision/docs/images/faulkner.jpg

サンプルコードをgithub に公開した。
https://github.com/ohwada/Android_Samples/tree/master/CloudVision2

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