LoginSignup
1
1

More than 5 years have passed since last update.

Emotion Recognitionをやってみる

Last updated at Posted at 2018-12-29

AzureのFaceAPIを使い感情センシングをしてみる

Azureのライセンス登録を実施してFaceAPIの使用登録をする

ライセンスグループの設定

  • FaceAPIの登録から
  • Endpointとkeyを取得する
  • EndpointはRegionのよって変わるの
  • keyは個別で取得

で、python環境で実施するときには、下記のSDKをインストール
https://github.com/Microsoft/Cognitive-Face-Python

インストール方法はページを参考に
サンプルプログラムを実行する

でサンプルプログラムを実行すると


#%%
import cognitive_face as CF

KEY = 'xxxxxxxxxxxxxxxxxxxxxxx'  # Replace with a valid Subscription Key here.
CF.Key.set(KEY)

BASE_URL = 'https://japanwest.api.cognitive.microsoft.com/face/v1.0'  # Replace with your regional Base URL
CF.BaseUrl.set(BASE_URL)

img_url = 'https://raw.githubusercontent.com/Microsoft/Cognitive-Face-Windows/master/Data/detection1.jpg'
result = CF.face.detect(img_url)
print(result)

入力画像は笑顔の眼鏡をかけた女性
https://raw.githubusercontent.com/Microsoft/Cognitive-Face-Windows/master/Data/detection1.jpg

Result

[{'faceId': '994e29b5-c2e1-4360-8ddd-bad720630fa2', 
'faceRectangle': {'top': 124, 'left': 459, 'width': 227, 'height': 227}}]

このままだと、感情がでないのね!ということで、調べてみるとオプションが必要な見たい
detectのオプションを追加して、emotionを返すように

result = CF.face.detect(img_url,attributes='emotion')

結果
happinessのスコアが1の検出ができた

[{'faceId': 'c42a5934-50a7-4c7c-bac9-fad476b90bbe',
 'faceRectangle': {'top': 124, 'left': 459, 'width': 227, 'height': 227}, 
 'faceAttributes': {'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 1.0, 'neutral': 0.0, 'sadness': 0.0, 'surprise': 0.0}}}]
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