LoginSignup
0
0

More than 1 year has passed since last update.

#11 PowerApps アプリ で撮影した画像を FaceAPI で感情分析してみました(累積分析)

Last updated at Posted at 2021-05-20

概要

PowerApps のカメラで撮影した画像を API Management 経由で FaceAPI に転送し、その画像の分析結果「感情、性別、年齢」を PoweApps に表示するアプリの実装手順を数回に分け記載しています。また、並行して、その分析結果を CosmosDB に保存しておき、PowerApps からの累積情報取得リクエストにより累積クエリ結果「感情分布、性別分布」を PowerApps に返し、円グラフ表示する機能の実装手順も複数回に分け記載します。なお、PowerApp の画面作成については省略し、APIコール部分とその戻り値の部分に焦点をあてて記載しています。
本アプリの全体構成は下図となります。
image.png

今回(第11回目)の構成箇所は下図の部分となります。
image.png

第11回目は、第4回 と同様に、PowerAppsコネクタ から 前回 作成した API Management(以下、APIM) -> Functions 経由で CosmosDB から感情毎の件数と性別毎の件数を Array型のJSON形式で取得できることを確認します。


実行環境

macOS Big Sur 11.3
Python 3.8.3


APIM から OpenAPI のエクスポート

PowerApps と APIM が属する Azureのテナント が異なるため、PowerApps から OpenAPI を通じて、APIM にアクセスさせます。そのため、前回作成した APIM の「iturufuncfacecosmos」から「OpenAPI v2 (JSON)」をエクスポートします。
image.png

ローカルに「iturufuncfacecosmos.swagger.json」というファイル名で OpenAPI がエクスポートされました。


PowerApps での OpenAPI のインポート

PowerApps のサイトに接続し、「データ」-「カスタムコネクタ」から上記でエクスポートされたJSONファイルをインポートします。
画面の手順に従い、コネクタ名には「iturufuncfacecosmos」を定義し、最後に「続行」ボタンを押します。
image.png


PowerApps のカスタムコネクタの定義

上記手順完了後、各タムコネクタの編集画面に切り替わります。任意でコネクタアイコンをアップロードします。必要であれば説明欄を記載します。
image.png

Swagger定義

画面上部の「Swaggerエディター」をONにし編集します。編集完了後、「コネクタの更新」を押します
image.png

Swaggerは下記のように編集しました。

swagger: '2.0'
info: {title: iturufuncfacecosmos, version: '1.0', description: Import from "iturufuncfacecosmos"
    Function App}
host: apim-ituru-faceapi.azure-api.net
basePath: /iturufuncfacecosmos
schemes: [https]
consumes: []
produces: []
paths:
  /HttpTriggerGet:
    get:
      description: HttpTriggerGet
      operationId: Get-httptriggerget
      summary: HttpTriggerGet
      produces: [application/json]
      responses:
        '200':
          description: OK
          schema:
            type: object
            properties:
              emo_graph:
                type: array
                items:
                  type: object
                  properties:
                    感: {type: string}
                    値: {type: integer, format: int32}
              gen_graph:
                type: array
                items:
                  type: object
                  properties:
                    性: {type: string}
                    値: {type: integer, format: int32}
          examples:
            application/json:
              emo_graph:
              - {感: 幸, 値: 1}
              - {感: 無, 値: 1}
              gen_graph:
              - {性: male, 値: 1}
              - {性: female, 値: 1}
definitions: {}
parameters: {}
responses: {}
securityDefinitions:
  API キー: {type: apiKey, in: header, name: Ocp-Apim-Subscription-Key}
security:
- API キー: []
tags: []

作成されたコネクタは以下のように表示されます。
image.png


PowerAppsコネクタからのテスト

カスタムコネクタ「iturufuncfacecosmos」の画面から「テスト」タブを選択します。
image.png

上記画面の「テスト操作」ボタンを押します。実行結果は以下となりました。
image.png

問題なく分析結果を取得できました。これで PowerAppsカスタムコネクタ から APIM -> Functions -> CosmosDB にて、想定する戻り値をArray型のJSON形式で取得できていることを確認できました。


次回について

次回(第12回)は、Flow から今回作成したカスタムコネクタ経由し、API Management -> Functions -> CosmosDB から感情毎の件数と性別毎の件数を Array型のJSON形式で取得できることを確認します。


参考情報

以下の情報を参考にさせていただきました。感謝申し上げます。
Microsoft (Office365) PowerAppsからFlowに、マップデータを渡して、配列データを受け取る方法
PowerApps / PowerAutomate カスタムコネクタを OpenAPI(Swagger)Specから作成する
Swaggerの記法まとめ

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