-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadFaces.py
58 lines (47 loc) · 1.79 KB
/
loadFaces.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
47
48
49
50
51
52
53
54
55
56
57
58
import numpy as np
import cv2
from sklearn.model_selection import train_test_split
def load_faces(Filename):
# Number of Persons in DataBase
N = 16
# Number of image faces for each Person in Database
Ni = 11
# Data of images in vector format
X = []
# Target of each image (rotules)
y = []
# String of filename to concatenated
filename_str = '{}'.format(Filename)
str_1 = 'subject0'
str_2 = 'subject'
str_3 = ['.centerlight', '.glasses', '.happy', '.leftlight', '.noglasses',
'.normal', '.rightlight', '.sad', '.sleepy', '.surprised', '.wink']
str_4 = '.pgm'
str_5 = '.jpg'
# Dimensionality of Vector Image
D = 100
for i in range(N): # Indice para os individuos
for j in range(Ni): # Indice para expressoes
if i < 9:
img_file = cv2.imread('{}/{}{}{}{}'.format(
filename_str, str_1, i + 1, str_3[j], str_4), 0)
# print('{} -> {}'.format((i+1), (j+1)))
img = cv2.resize(img_file, (D, D))
img = np.reshape(img, (D * D))
X.append(img)
y.append(i + 1)
elif i >= 9 and i < 15:
img_file = cv2.imread(
'{}/{}{}{}{}'.format(filename_str, str_2, i + 1, str_3[j], str_4), 0)
img = cv2.resize(img_file, (D, D))
img = np.reshape(img, (D * D))
X.append(img)
y.append(i + 1)
else:
img_file = cv2.imread('{}/{}{}{}{}'.format(
filename_str, str_2, i + 1, str_3[j], str_5), 0)
img = cv2.resize(img_file, (D, D))
img = np.reshape(img, (D * D))
X.append(img)
y.append(i + 1)
return [X, y]