Upload make_RGB_dataset.py
Browse files- make_RGB_dataset.py +88 -0
make_RGB_dataset.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'''
|
2 |
+
1. Please first extract RGB folder in each video folder in each scene folder and organize as below:
|
3 |
+
|-- RGB_file
|
4 |
+
|-- 1
|
5 |
+
|-- 1.1
|
6 |
+
...
|
7 |
+
|-- 1.4
|
8 |
+
# (end of folder)
|
9 |
+
|
|
10 |
+
|-- 2
|
11 |
+
|-- 2.1
|
12 |
+
|-- color (folder)
|
13 |
+
#
|
14 |
+
|-- 2.2
|
15 |
+
|-- color
|
16 |
+
#
|
17 |
+
|-- 2.3
|
18 |
+
|-- color
|
19 |
+
#
|
20 |
+
|-- 2.4
|
21 |
+
|-- color
|
22 |
+
#
|
23 |
+
|-- 2.5
|
24 |
+
|-- color
|
25 |
+
#
|
26 |
+
|
|
27 |
+
...
|
28 |
+
|
|
29 |
+
|-- 11
|
30 |
+
|-- 11.1
|
31 |
+
...
|
32 |
+
|-- 11.5
|
33 |
+
#
|
34 |
+
|
|
35 |
+
#
|
36 |
+
|
37 |
+
|
38 |
+
and run the code below
|
39 |
+
'''
|
40 |
+
import h5py
|
41 |
+
import numpy as np
|
42 |
+
import io
|
43 |
+
from PIL import Image
|
44 |
+
import os
|
45 |
+
from tqdm import tqdm
|
46 |
+
|
47 |
+
f = h5py.File("RGB_dataset.hdf5", "w")
|
48 |
+
|
49 |
+
# saving path: f["color/scene/video/"]
|
50 |
+
# color path:
|
51 |
+
color_file_path = "RGB_file"
|
52 |
+
color_grp = f.require_group("color")
|
53 |
+
|
54 |
+
for scene in tqdm(os.listdir(color_file_path)):
|
55 |
+
print(scene)
|
56 |
+
scene_file_path = os.path.join(color_file_path, scene)
|
57 |
+
scene_grp = color_grp.require_group(scene)
|
58 |
+
for video in tqdm(os.listdir(scene_file_path)):
|
59 |
+
if video=="groundtruth":
|
60 |
+
continue
|
61 |
+
video_grp = scene_grp.require_group(video)
|
62 |
+
video_color_path = os.path.join(scene_file_path,video,"color")
|
63 |
+
for image in tqdm(os.listdir(video_color_path)):
|
64 |
+
img_path = os.path.join(video_color_path, image)
|
65 |
+
with open(img_path, 'rb') as img_f:
|
66 |
+
binary_data = img_f.read()
|
67 |
+
binary_data_np = np.asarray(binary_data)
|
68 |
+
dset = video_grp.create_dataset(f'{image[:-4]}', data=binary_data_np)
|
69 |
+
f.close()
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
|