-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_images.py
79 lines (68 loc) · 3.14 KB
/
load_images.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import glob
import natsort
import numpy as np
import cv2
def load_images(dataset_name, frame_skip):
images = []
subjects = []
subjectsVideos = []
print('Loading images from dataset', dataset_name)
# For dataset CASME_3
if(dataset_name == 'CASME_3'):
for i, dir_sub in enumerate(natsort.natsorted(glob.glob("../dataset/"+ dataset_name + "/data/*"))):
print('Subject: ' + dir_sub.split('/')[-1])
subjects.append(dir_sub.split('/')[-1].split('.')[-1])
subjectsVideos.append([])
for dir_sub_vid in natsort.natsorted(glob.glob(dir_sub + "/*")):
subjectsVideos[-1].append(dir_sub_vid.split('/')[-1]) # Ex:'CASME_sq/data/spNO.1/a'
image = []
count = 0
for dir_sub_vid_img in natsort.natsorted(glob.glob(dir_sub_vid +"/color/*.jpg")):
while int(dir_sub_vid_img.split('/')[-1].split('.')[0]) != count:
image.append(cv2.imread(dir_sub_vid_img, 0)) # 0 / 1
count += 1
print('Done -> ' + dir_sub_vid.split('/')[-1])
images.append(np.array(image))
# For dataset SAMMLV
elif(dataset_name == 'SAMMLV'):
for i, dir_vid in enumerate(natsort.natsorted(glob.glob("../dataset/"+ dataset_name + "/SAMM_longvideos/*"))):
subject = dir_vid.split('/')[-1].split('_')[0]
if (subject not in subjects): #Only append unique subject name
subjects.append(subject)
subjectsVideos.append([])
subjectsVideos[-1].append(dir_vid.split('/')[-1])
image = []
i = 0
for dir_vid_img in natsort.natsorted(glob.glob(dir_vid + "/*.jpg")):
if i % frame_skip ==0:
image.append(cv2.imread(dir_vid_img, 0))
i += 1
image = np.array(image)
print('Done -> ' + dir_vid.split('/')[-1])
images.append(image)
print('Loading images from dataset', dataset_name, 'All Done')
return images, subjects, subjectsVideos
def load_information(dataset_name, frame_skip):
subjects = []
subjectsVideos = []
print('Loading images from dataset', dataset_name)
# For dataset CASME_3
if(dataset_name == 'CASME_3'):
for i, dir_sub in enumerate(natsort.natsorted(glob.glob("../dataset/"+ dataset_name + "/data/*"))):
print('Subject: ' + dir_sub.split('/')[-1])
subjects.append(dir_sub.split('/')[-1].split('.')[-1])
subjectsVideos.append([])
for dir_sub_vid in natsort.natsorted(glob.glob(dir_sub + "/*")):
subjectsVideos[-1].append(dir_sub_vid.split('/')[-1]) # Ex:'CASME_sq/data/spNO.1/a'
print('Done -> ' + dir_sub_vid.split('/')[-1])
# For dataset SAMMLV
elif(dataset_name == 'SAMMLV'):
for i, dir_vid in enumerate(natsort.natsorted(glob.glob("../dataset/"+ dataset_name + "/SAMM_longvideos/*"))):
subject = dir_vid.split('/')[-1].split('_')[0]
if (subject not in subjects): #Only append unique subject name
subjects.append(subject)
subjectsVideos.append([])
subjectsVideos[-1].append(dir_vid.split('/')[-1])
print('Done -> ' + dir_vid.split('/')[-1])
print('Loading images from dataset', dataset_name, 'All Done')
return subjects, subjectsVideos