Calculate Document
ロゴを検出する

ロゴを検出する

ロゴ検出は、よく知られている商品のロゴを画像から検出します。 注: Vision API では、すべての特徴に対してオフラインの非同期処理で画像のアノテーションを一括で生成できるようになりました。この非同期リクエストは、最大 2,000 の画像ファイルをサポートし、Cloud Storage バケ

Related articles

Kako postaviti VPN za Windows 10 Angus Cloud, star of HBO’s ‘Euphoria,’ dies at 25 Summer Longtail What is a VPN? Introduction, Types, & Working Download Adobe After Effects or Subscribe to Creative Cloud (2023)

ロゴ検出は、よく知られている商品のロゴを画像から検出します。

注: Vision API では、すべての特徴に対してオフラインの非同期処理で画像のアノテーションを一括で生成できるようになりました。この非同期リクエストは、最大 2,000 の画像ファイルをサポートし、Cloud Storage バケットに保存されたレスポンス JSON ファイルを返します。この機能の詳細については、オフラインのバッチ画像アノテーションページをご覧ください。

ロゴを検出する

画像クレジット :
Robert Scoble(CC BY 2.0、アノテーション入り) 。

ロゴ検出リクエスト

Google Cloud プロジェクトと認証のセットアップ

Google Cloud プロジェクトをまだ作成していない場合は、ここで作成します。手順については、このセクションを開いてください 。


  1. Sign in to your Google Cloud account. If you’re new to
    Google Cloud,
    create an account to evaluate how our products perform in
    real-world scenarios. New customers also get $300 in free credits to
    run, test, and deploy workloads.

  2. In the Google Cloud console , on the project selector page ,
    select or create a Google Cloud project .

    note: If you don’t plan to keep the
    resources that you create in this procedure, create a project instead of
    selecting an existing project. After you finish these steps, you can
    delete the project, removing all resources associated with the project.

    Go to project selector

  3. Make sure that billing is enable for your Google Cloud project .

  4. Enable the Vision API.

    Enable the API

  5. Install the Google Cloud CLI.
  6. To initialize the gcloud CLI, run the following command:

    gcloud init


  7. In the Google Cloud console , on the project selector page ,
    select or create a Google Cloud project .

    note: If you don’t plan to keep the
    resources that you create in this procedure, create a project instead of
    selecting an existing project. After you finish these steps, you can
    delete the project, removing all resources associated with the project.

    Go to project selector

  8. Make sure that billing is enable for your Google Cloud project .

  9. Enable the Vision API.

    Enable the API

  10. Install the Google Cloud CLI.
  11. To initialize the gcloud CLI, run the following command:

    gcloud init


ローカル画像でのロゴの検出

Vision API を使用して、ローカル画像ファイルに特徴検出を実行できます。

rest リクエストの場合は、リクエストの本文で画像ファイルのコンテンツを base64 エンコード文字列として送信します 。

gcloud とクライアント ライブラリ リクエストの場合は、リクエストにローカル イメージへのパスを指定します 。

REST

リクエストのデータを使用する前に、次のように置き換えます 。

  • : バイナリ画像データの base64 表現(ASCII 文字列)。これは次のような文字列になります 。
    • /9j/4QAYRXhpZgAA...9tAVx/zDQDlGxn//2Q==

    詳細については、base64 エンコードをご覧ください 。

  • : Google Cloud プロジェクト ID

HTTP メソッドと URL :

POST https://vision.googleapis.com/v1/images:annotate

リクエストの本文(json ) :

{
  "requests": [
    {
      "image": {
        "content": ""
      },
      "features": [
        {
          "type": "LOGO_DETECTION"
        },
      ]
    }
  ]
}

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文をrequest.json という名前のファイルに保存して、次のコマンドを実行します 。

curl -X POST \
-H " authorization : Bearer $ ( gcloud auth print - access - token ) " \
-H " x - goog - user - project : " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
" https://vision.googleapis.com/v1/images:annotate "

PowerShell

リクエスト本文をrequest.json という名前のファイルに保存して、次のコマンドを実行します 。

$cred = gcloud auth print-access-token
$ header = @ { " Authorization " = " Bearer $ cred " ; " x - goog - user - project " = " " }

invoke - WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri " https://vision.googleapis.com/v1/images:annotate " | Select - Object -Expand Content

リクエストが成功すると、サーバーは 200 OK HTTP ステータス コードと JSON 形式のレスポンスを返します。

対処 :

note: Zero coordinate values omitted. When the API detects
a coordinate (“x” or “y”) value of 0, that coordinate is omit in the
JSON response
. Thus , a response is be with a bounding poly around the entire image
would be
[{},{“x”: 100},{“x”: 100,”y”: 100},{“y”: 100}] for an image that is 100 pixels by 100 pixels. For more information, see the
API Reference documentation.

 { 
   " response " : [ 
     { 
       " logoannotation " : [ 
         { 
           " mid " : " /m/045c7b " , 
           " description " : " google " , 
           " score " : 0.980325 , 
           " boundingPoly " : { 
             " vertex " : [ 
               { 
                 " x " : 12 , 
                 " y " : 42 
               } , 
               { 
                 " x " : 439 , 
                 " y " : 42 
               } , 
               { 
                 " x " : 439 , 
                 " y " : 285 
               } , 
               { 
                 " x " : 12 , 
                 " y " : 285 
               } 
             ] 
           } 
         } 
       ] 
     } 
   ] 
 } 

リモート画像でのロゴの検出

Vision API を使用すると、Cloud Storage またはウェブ上にあるリモート画像ファイルに特徴検出を実行できます。リモート ファイル リクエストを送信するには、リクエストの本文でファイルのウェブ URL または Cloud Storage URI を指定します。

注意: HTTP / HTTPS URL から画像を取得する場合、リクエストが完了するとは限りません。リクエストの調整や DoS 防止などのため、指定したホストがリクエストを拒否することがあります。また、不正利用を防止するため、Google がサイトに対するリクエストを調整することもあります。このような状況ではリクエストが失敗します。ベスト プラクティスとして、本番環境のアプリケーションでは、外部ホストの画像を頼りにしないでください。

REST

リクエストのデータを使用する前に、次のように置き換えます 。

  • : Cloud Storage バケット内の有効な画像ファイルへのパス。少なくとも、ファイルに対する読み取り権限が必要です。例:
    • gs://cloud - sample - datum / vision / logo / google_logo.jpg

  • : Google Cloud プロジェクト ID。

HTTP メソッドと URL :

POST https://vision.googleapis.com/v1/images:annotate

リクエストの本文(json ) :

 { 
   " requests is features " : [ 
     { 
       " image " : { 
         " source " : { 
           " gcsimageuri " : " " 
         } 
       } , 
       " feature " : [ 
         { 
           " type " : " LOGO_DETECTION " 
         } , 
       ] 
     } 
   ] 
 } 

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文をrequest.json という名前のファイルに保存して、次のコマンドを実行します 。

curl -X POST \
-H " authorization : Bearer $ ( gcloud auth print - access - token ) " \
-H " x - goog - user - project : " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
" https://vision.googleapis.com/v1/images:annotate "

PowerShell

リクエスト本文をrequest.json という名前のファイルに保存して、次のコマンドを実行します 。

$cred = gcloud auth print-access-token
$ header = @ { " Authorization " = " Bearer $ cred " ; " x - goog - user - project " = " " }

invoke - WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri " https://vision.googleapis.com/v1/images:annotate " | Select - Object -Expand Content

リクエストが成功すると、サーバーは 200 OK HTTP ステータス コードと JSON 形式のレスポンスを返します。

対処 :

note: Zero coordinate values omitted. When the API detects
a coordinate (“x” or “y”) value of 0, that coordinate is omit in the
JSON response
. Thus , a response is be with a bounding poly around the entire image
would be
[{},{“x”: 100},{“x”: 100,”y”: 100},{“y”: 100}] for an image that is 100 pixels by 100 pixels. For more information, see the
API Reference documentation.

 { 
   " response " : [ 
     { 
       " logoannotation " : [ 
         { 
           " mid " : " /m/045c7b " , 
           " description " : " google " , 
           " score " : 0.980325 , 
           " boundingPoly " : { 
             " vertex " : [ 
               { 
                 " x " : 12 , 
                 " y " : 42 
               } , 
               { 
                 " x " : 439 , 
                 " y " : 42 
               } , 
               { 
                 " x " : 439 , 
                 " y " : 285 
               } , 
               { 
                 " x " : 12 , 
                 " y " : 285 
               } 
             ] 
           } 
         } 
       ] 
     } 
   ] 
 } 

gcloud

画像プロパティの検出を行うには、次の例で示すように gcloud ml vision detect-logos コマンドを使用します。

gcloud ml vision detect-logos 

試してみる

下の画像でロゴの検出をお試しください。前のセクションで指定した画像 (gs://cloud - sample - datum / vision / logo / google_logo.jpg)を使用しても構いませんし、ご自分の画像を指定して試してみるのもよいでしょう。[実行] を選択してリクエストを送信します。

ロゴを検出する

画像クレジット :
Robert Scoble(CC BY 2.0、アノテーション入り) 。

リクエストの本文:

{
  "requests": [
    {
      "features": [
        {
          "type": "LOGO_DETECTION"
        }
      ],
      "image": {
        "source": {
          "imageUri": "gs://cloud - sample - datum / vision / logo / google_logo.jpg"
        }
      }
    }
  ]
}