-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmotion_Feature_Analyze.py
46 lines (33 loc) · 1.62 KB
/
Emotion_Feature_Analyze.py
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
39
40
41
42
43
44
45
46
import numpy as np
NUMBER_FACIAL_LANDMARKS = 68 # number of facial landmarks
directory = './폴수학학교/2019 가을학기/전공 연구/Emotion_Feature_Analyze/dataset/'
def LoadDataset(emotion):
dataset = list()
path = directory + emotion + '.npy'
datasetTemp = np.load(path, allow_pickle = True) # 3 dimension array : (x, y)
for i in range(len(datasetTemp)): # index of face
if datasetTemp[i]:
dataset.append(datasetTemp[i])
return np.array(dataset)
def AnalyzeDataset(dataset, dataCount):
avgList = np.zeros((NUMBER_FACIAL_LANDMARKS, 2))
xSum = list(0 for _ in range(NUMBER_FACIAL_LANDMARKS))
ySum = list(0 for _ in range(NUMBER_FACIAL_LANDMARKS))
for i in range(dataCount): # index of face
for j in range(NUMBER_FACIAL_LANDMARKS): # index of facial landmark
xSum[j] += float(dataset[i][j][1])
ySum[j] += float(dataset[i][j][2])
for i in range(NUMBER_FACIAL_LANDMARKS): # index of facial landmark
avgList[i][0] = xSum[i] / dataCount
avgList[i][1] = ySum[i] / dataCount
return avgList
def ExportAnalyzedDataset(emotion, avgList, dataCount):
path = directory + emotion + 'AnalyzedData.txt'
datasetFile = open(path, 'w')
for i in range(NUMBER_FACIAL_LANDMARKS): # index of facial landmark
datasetFile.write('%f %f\n' % (avgList[i][0], avgList[i][1]))
datasetFile.close()
emotion = input('emotion: ')
dataset = LoadDataset(emotion)
avgList = AnalyzeDataset(dataset, len(dataset))
ExportAnalyzedDataset(emotion, avgList, len(dataset))