File size: 1,222 Bytes
4b34522
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3476c2
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
from feat import Detector

# 検出器の定義
detector = Detector()


class EmotionAnalyzer:
    def __init__(self, img_file_path_list):
        self.img_file_path_list = img_file_path_list

    def create_emotion_dataflame(self):
        """
        イメージファイルの分析結果をデータフレーム化
        """
        emotions_deg_list = []
        result_detections_list = []
        for img_file_path in self.img_file_path_list:
            result_emotions_mean, result_detections = self.analyze_emotion(img_file_path)
            emotions_deg_list.append(result_emotions_mean)
            result_detections_list.append(result_detections)

        df_emotion_result = pd.DataFrame(emotions_deg_list, index=self.img_file_path_list)
        df_emotion_result['detections'] = result_detections_list

        return df_emotion_result

    @staticmethod
    def analyze_emotion(img_file_path):
        """
        イメージファイルから感情を分析
        """
        # 検出器の定義
        detector = Detector()
        result = detector.detect_image(img_file_path)
        result_emotions_mean = result.emotions.mean()
        return result_emotions_mean, result