1
1

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 5 years have passed since last update.

Azure Cognitive Services の Bing Image Search 機能を使ってみる

Last updated at Posted at 2019-10-15

今回は Cognitive Services 機能の一つである Bing Search を使って、テキストから画像を検索するデモを試してみる。

Bing Image Search とは?

Microsoft の Bing Image Search の紹介ページには以下の様に記載している。
https://azure.microsoft.com/ja-jp/services/cognitive-services/bing-image-search-api/

Bing Image Search API v7 は、Web での画像検索に役立ちます。検索結果にはサムネイル、画像の完全な URL、発行元 Web サイトの情報、画像のメタデータなどが含まれます。API v7 であれば、画像検索で特定の結果を簡単に見つけられる新しい並べ替えオプションやフィルター オプションが利用でき、結果のページングも可能です。

つまり単純に「犬」といった固有名詞の検索だけでなく、「かわいい 動物」といった形で検索することが可能となっているみたいです。実際にデモページで「Cute Animals」と検索すると可愛らしい動物たちの画像が返ってきました。
image.png

この開発コードが GitHub に公開されていたので、今回はそれをいじってみて、実際に自分の WebPage から Bing Image Search が呼び出せるか確認してみようと思います。

Azure Portal から Bing Image Search のデプロイ

まずは Azure Portal からBing Search v7 をデプロイします。リソースの作成から「Bing」と検索すると1番目か2番目に出てくると思います。作成するとき、今回はデモで実施するため、フリーの「F0」プランを選択します。Cognitive Services は API を申請するのみのため、VM等と比べると早くデプロイが終わります。
image.png
Azure Bing V7 のデプロイが終わったら、Key をコピーしておきます。

GitHub からソースコードを入手し、変更箇所を書き換える

Microsoft が公開しているコードを自分の PC 環境にデプロイします。Clone が完了したら、今回使用する Bing Image Services が入っているディレクトリに移動します。

git clone https://github.com/Azure-Samples/cognitive-services-REST-api-samples.git
Tutorials/Bing-Image-Search/

無事に Clone と該当ディレクトリへの移動が完了したら、public/js の中にある Script を変更します。
一番上に Key を入力する行があるので、そこに先ほどコピーした Key を入力します。
image.png

実際に使用してみる

ここまで出来たら実際にデプロイしてみます。
node js でのデプロイ方法、「npm install」と「node app.js」をコマンドで打つと、ローカルでアプリケーションが実行され、ブラウザからアクセスできるようになります。実際にアクセスし、「くまのみ」と検索すると以下のような画像がかえってきました。

image.png

以前作成した、Custom Vision を使って判別された画像とテキストを使って、類似の画像を検索する、というのも簡単にできそうです。
https://qiita.com/komiyasa/items/0ba847d7359817ea2dd5

参考URL

GitHub ソースコード
https://github.com/Azure-Samples/cognitive-services-REST-api-samples/tree/master/Tutorials/Bing-Image-Search

Create a single-page app using the Bing Image Search API
https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/tutorial-bing-image-search-single-page-app

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?