概要
Microsoft Cognitive ServicesのFaceを使ってみた。
無料ゲスト使用で、7日間、20回/分、30000回。
-
Emotionプレビューは Faceに統合されたのこと。
一般提供の Face API に感情認識機能が統合されました。既存のお客様向けの Emotion API のプレビューは 2019 年 2 月 15 日で終了します。今後は Face API の感情認識機能をお試しください。
-
face/#recognition 感情認識
Face API に感情認識が統合され、怒り、軽蔑、嫌悪感、恐怖、喜び、中立、哀しみ、驚きといった、それぞれの顔が浮かべている感情の信頼度が返されるようになりました。これらの感情は、文化が異なっても特定の表情を伴って広く交わされると理解されています。
へーへーへー。
お試し
https://azure.microsoft.com/ja-jp/services/cognitive-services/face/ のページで、URL送信/画像のUploadにて、顔検証/顔検出/感情認識のデモができる。
tifはサポートしていない。
We do not support this file type. Please use one of the following: .jpeg, .png, .jpg, .gif
APIにて使用
-
Face APIキー取得
- https://azure.microsoft.com/ja-jp/services/cognitive-services/face/ から、Faceを試す をおす
- ゲストの [はじめる]
- 使用条件の同意にチェックして、[次へ>]
- サインインして API を作成する (うまいアカウントがないときは、Microsoftのを作成するとよいかと..)
- 7日間有効なAPIキーがもらえる
- APIキーがわからなくなったら、もう一回、[Faceを試す]から、やると、"この製品は、お使いのサブスクリプションにすでに追加されています。"のメッセージと一緒に、取得しているAPIキーが表示される
エンドポイントとAPIキーをメモる
-
クイックスタートガイド > クイックスタート > cURL
- コマンドプロンプトをひらく
下のサンプルコードの - <Subscription Key>を APIキーに置き換え
-
https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect
を使用するエンドポイントに置き換え - (オプション)
"{\"url\":...
のところをお好みの画像のURLへ -
コマンドプロンプトにペーストして実行
サンプルコードcurl -H "Ocp-Apim-Subscription-Key: <Subscription Key>" "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise" -H "Content-Type: application/json" --data-ascii "{\"url\":\"https://upload.wikimedia.org/wikipedia/commons/c/c3/RH_Louise_Lillian_Gish.jpg\"}"
結果がJSONにて出てくる。
- コマンドプロンプトをひらく
cURL
-
実行例
実行例_WikipediaのLenna画像Microsoft Windows [Version 10.0.17134.285] (c) 2018 Microsoft Corporation. All rights reserved. C:\>curl -H "Ocp-Apim-Subscription-Key: 8092c818c16c42d1aa5b8289a7f81ca3" "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise" -H "Content-Type: application/json" --data-ascii "{\"url\":\"https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png\"}" [{"faceId":"a643b1a3-b32e-4531-a932-da3c7ff56c0d","faceRectangle":{"top":225,"left":215,"width":166,"height":166},"faceAttributes":{"smile":0.0,"headPose":{"pitch":0.0,"roll":0.3,"yaw":22.5},"gender":"female","age":24.0,"facialHair":{"moustache":0.0,"beard":0.0,"sideburns":0.0},"glasses":"NoGlasses","emotion":{"anger":0.0,"contempt":0.0,"disgust":0.0,"fear":0.0,"happiness":0.0,"neutral":1.0,"sadness":0.0,"surprise":0.0},"blur":{"blurLevel":"low","value":0.16},"exposure":{"exposureLevel":"goodExposure","value":0.59},"noise":{"noiseLevel":"low","value":0.24},"makeup":{"eyeMakeup":true,"lipMakeup":true},"accessories":[{"type":"headwear","confidence":0.98}],"occlusion":{"foreheadOccluded":true,"eyeOccluded":false,"mouthOccluded":false},"hair":{"bald":0.0,"invisible":true,"hairColor":[]}}}] C:\>
-
JSON結果を整形
[ { "faceId": "a643b1a3-b32e-4531-a932-da3c7ff56c0d", "faceRectangle": { "top": 225, "left": 215, "width": 166, "height": 166 }, "faceAttributes": { "smile": 0, "headPose": { "pitch": 0, "roll": 0.3, "yaw": 22.5 }, "gender": "female", "age": 24, "facialHair": { "moustache": 0, "beard": 0, "sideburns": 0 }, "glasses": "NoGlasses", "emotion": { "anger": 0, "contempt": 0, "disgust": 0, "fear": 0, "happiness": 0, "neutral": 1, "sadness": 0, "surprise": 0 }, "blur": { "blurLevel": "low", "value": 0.16 }, "exposure": { "exposureLevel": "goodExposure", "value": 0.59 }, "noise": { "noiseLevel": "low", "value": 0.24 }, "makeup": { "eyeMakeup": true, "lipMakeup": true }, "accessories": [ { "type": "headwear", "confidence": 0.98 } ], "occlusion": { "foreheadOccluded": true, "eyeOccluded": false, "mouthOccluded": false }, "hair": { "bald": 0, "invisible": true, "hairColor": [] } } } ]
-
画像界で有名なレナ様は、"neutral": 1 (中立)... とのこと。
感情"emotion": { "anger": 0, 怒り "contempt": 0, 軽蔑 "disgust": 0, 嫌悪感 "fear": 0, 恐怖 "happiness": 0, 喜び "neutral": 1, 中立 "sadness": 0, 哀しみ "surprise": 0 驚き },
その他
- キー1と2のどちらか使えばいいっぽい
- 複数人の写真も認識する
- 写真に取られるときの表情の改善の練習に使用したい...
(スマイルぅ~して、写真をとられてるはずが、、そうなっていないらしい。。)