LoginSignup
0
0

pythonでFERを使用して感情を数値化する

Posted at

概要

今回はpythonでFERを使用して感情を数値化する方法について記載していきます。
勉強用に簡易的に記載していますので、ご了承ください。

実行環境

・windows:Windows11Pro 23H2
・Python 3.12.3

参考サイト

スクリプト

emotion.py
from fer import FER
import matplotlib.pyplot as plt

# 画像の取得
test_image_one = plt.imread("顔が映っている画像のパス")
emo_detector = FER(mtcnn=True)
captured_emotion = emo_detector.detect_emotions(test_image_one)

# 全ての感情の取得
INITDATA = 0
EMOTIONS = {"angry":INITDATA,"disgust":INITDATA,"fear":INITDATA, "happy":INITDATA, "sad":INITDATA, "surprise":INITDATA,"neutral":INITDATA}
for key in EMOTIONS.keys():
    if captured_emotion[0]['emotions'][key]:
        EMOTIONS[key] = captured_emotion[0]['emotions'][key]


# 全ての感情を抽出
print(EMOTIONS)

# 最も高い感情とその値を抽出
dominant_emotion = max(EMOTIONS.items(), key=lambda x: x[1])
print(dominant_emotion)

# 感情をグラフ化する
figure_diagram = EMOTIONS.items()
figure_diagram = sorted(figure_diagram)
x, y = zip(*figure_diagram)

plt.plot(x, y)
plt.show()

実行結果

1)ログ出力
emotion_output.jpg

2)グラフ
emotion.png

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