Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Latest commit

 

History

History
237 lines (160 loc) · 11.3 KB

README-ja.md

File metadata and controls

237 lines (160 loc) · 11.3 KB

Vision App - イメージのタグ付けとフェイスディテクションをIBM Cloud(Bluemix)で作成するサンプルiOSアプリケーション

Vision Appは、自動でイメージにタグを付けて顔認識をする、サンプルiOSアプリケーションです。 これらの仕組みは、IBM visual recognitionテクノロジーが使用されています。

写真を撮るか、既存の画像を選択し、アプリケーションでタグのリストを作成し、画像内の人物、建物、オブジェクトを検出します。結果はインターネットで共有できます。

Overview

IBM Cloud(Bluemix)で作成するこのアプリは以下の機能を使用します:

  • Watson Visual Recognition
  • OpenWhisk
  • Cloudant

Architecture

vision_analysis digraph G { node [fontname = "helvetica"] /* stores image */ app -> cloudant /* analyzes the image */ app -> openwhisk {rank=same; app -> openwhisk -> watson [style=invis] } /* openwhisk reads from cloudant */ cloudant -> openwhisk /* whisk passes image to visual recognition */ openwhisk -> watson /* whisk provides result */ openwhisk -> app /* services on top */ {rank=source; cloudant } /* styling ****/ cloudant [shape=circle style=filled color="%234E96DB" fontcolor=white label="Cloudant"] watson [shape=circle style=filled color="%234E96DB" fontcolor=white label="Watson\nVisual\nRecognition"] openwhisk [shape=circle style=filled color="%2324B643" fontcolor=white label="OpenWhisk"] } vision_analysis

このアプリケーションは、画像をCloudantデータベースに送信します。次に、OpenWhiskアクションを呼び出して画像を分析し、分析結果を返します。

このアプリケーションは、ユースケースの1例です。この例で実装されているOpenWhiskアクションを利用した別のユースケースは、検索機能を向上させるために画像をライブラリに自動的に分類します。同じOpenWhiskアクションですが、別のコンテキストで使用します。実際、このアクションでは、単一のサーバーを展開または管理することなく、クラウド内のイメージ分析用のマイクロサービスを作成しました。

事前作業

環境の準備

コードの取得

  • このリポジトリをローカル環境へCloneするか、ターミナルから次のコマンドを実行して下さい。

    git clone https://github.com/IBM-Bluemix/openwhisk-visionapp.git
    
  • または this archive から、圧縮したファイルをダウンロードして下さい。

IBM Cloud (Bluemix) サービス

  1. IBM Cloud (Bluemix) コンソールを開きます

  2. Cloudant NoSQL DBサービスインスタンスを次の名前で作成します cloudant-for-vision

  3. Cloudantのダッシュボードを開き、新しいデータベースを次の名前で作成します openwhisk-vision

  4. Watson Visual Recognitionサービスインスタンスを次の名前で作成します visualrecognition-for-vision

Note: もし既にこれらのサービスインスタンスを作成済みでしたら、それらを再利用しても結構です。その場合、Swiftのコードで指定しているサービス名を適宜置き換えて下さい。

Cloud Functions (OpenWhisk) Actions

  1. 次のコマンドで既存のアクションリストを確認できます。
wsk list
  1. 次のコマンドで、新たにアクションを作成します。URLやKeyは適宜自分の環境のものに置き換えて下さい。これらの情報は、IBM Cloud (Bluemix)上の各サービスの資格情報から確認することができます。資格情報が無い場合は新規作成して下さい。
wsk action create -p cloudantUrl [URL] -p cloudantDbName openwhisk-vision -p watsonApiKey [123] vision-analysis analysis.js

XCodeでの実装

iOSアプリケーションで使用するために、�作成したIBM Cloud (Bluemix)�の各サービスの情報をSwiftのコード上へ�記述します。Cloudantの資格情報、OpenWhiskの名前空間(namespace)とAppKeyが必要になります。

  1. vision.xcworkspace を、XCodeで開きます

  2. vision/vision/model/ServerlessAPI.swift を開きます

  3. CloudantUrl へ、Cloudantサービスの資格情報に記載されているURLを記述します

  4. WhiskAppKeyWhiskAppSecret へ、Cloud Functions (OpenWhisk)の資格情報にある値を記述します これらの値は、 iOS SDK configuration page から取得するか、以下のCLIコマンドで取得することができます

wsk property get --auth
whisk auth kkkkkkkk-kkkk-kkkk-kkkk-kkkkkkkkkkkk:tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt

コロンの前の文字列がkey、後ろの文字列がsecretです。

  1. ファイルを保存します

アプリケーションのビルド・実行

With the iOS simulator

  1. iOS10以降では、カメラアクセスの�目的を設定しないと強制終了します info.plist を設定します

  Key:NSCameraUsageDescription

  Description:任意の説明文

  1. iPhone 6s またはそれ以降をターゲットに指定して、Xcodeで実行します

  1. 既存の写真を選択します

Note: To add pictures to the simulator, go to the home screen (Cmd+Shift+H). Drag and drop images from the Finder to the simular window. This will open the Photos app and you should see your images.

  1. 写真はIBM Cloud上のVisual Recognition APIへ送られ、解析結果が帰ってきます

Results are made of the faces detected in the picture and of tags returned by Watson. The tags with the highest confidence score are pre-highlighted. The highlighted tags will be used when sharing the picture. You can tap tags to toggle their state.

  1. �Shareボタンを押すと、iOS標準のシェア画面が開きます

Note: to configure a Twitter account, go to the Settings app on the simulator. Under Twitter, add your account (no need for the Twitter app to be installed). You can go back to the home screen with Cmd+Shift+H

  1. 例えばTwitterを選択します

The picture and the highlighted tags are included in the message. The message can be edited before posting.

ソースコード構成

IBM Cloud Functions (OpenWhisk)

analysis.js は、画像解析を行うためのJavaScriptコードを含んでいます。

  1. 画像データをCloudantドキュメントから取り出します。そのデータは、iOSアプリケーションによって"image.jpg"という名前でアタッチされます。
  2. 画像ファイルとしてローカルへ保存します。
  3. 必要に応じ、Watsonサービスで定められたサイズへリサイズします。
  4. Watson API を呼び出します。
  5. 解析結果を返却します。

アクションはそれぞれ非同期で実行します。

iOS

File Description
ServerlessAPI.swift Stores the image in Cloudant and executes the analysis OpenWhisk action, waiting for the result.
Result.swift Encapsulates the JSON result
HomeController.swift Manages the selection of an existing picture and taking a picture from the camera
ResultController.swift Uses ServerlessAPI to send the image for processing and then display the results of the analysis
FacesController.swift Embedded in ResultController if handles the face collection view
FaceCellRenderer.swift Renders a face in the FacesController

Contribute

希望の変更点はどうぞプルリクエストを送って下さい。 これは IBM-Bluemix/openwhisk-visionapp に直接送るのが効率的と思います。

トラブルシューティング

OpenWhisk

アクティベーションへのポーリングは、Cloud Functions (OpenWhisk)のアクションをデバッグするのに便利です。 以下を実行します。

wsk activation poll

解析向けに画像をSubmitします。

全てが上手く実行されたときの典型的なアクティベーションログはこんな感じです。

Activation: vision-analysis (123fb4230902822202029fff436a94be745)
2016-02-23T16:17:53.955350233Z stdout: [ 49382920fdb022039403934b3bd33d00 ] Processing image.jpg from document
2016-02-23T16:17:59.847872226Z stdout: [ 49382920fdb022039403934b3bd33d00 ] OK

iOS

アプリケーションはアップロード、解析、UIの更新など、いくつかのステートメントをコンソールへ出力します。 ServerlessAPI.swiftの定数を正しいかどうか見直して下さい。

Credits

The application uses:

License

See License.txt for license information.