File size: 1,639 Bytes
9119cc6 |
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 80 81 82 83 84 85 86 87 88 89 |
'''
1. Please first extract RGB folder in each video folder in each scene folder and organize as below:
|-- RGB_file
|-- 1
|-- 1.1
...
|-- 1.4
# (end of folder)
|
|-- 2
|-- 2.1
|-- color (folder)
#
|-- 2.2
|-- color
#
|-- 2.3
|-- color
#
|-- 2.4
|-- color
#
|-- 2.5
|-- color
#
|
...
|
|-- 11
|-- 11.1
...
|-- 11.5
#
|
#
and run the code below
'''
import h5py
import numpy as np
import io
from PIL import Image
import os
from tqdm import tqdm
f = h5py.File("RGB_dataset.hdf5", "w")
# saving path: f["color/scene/video/"]
# color path:
color_file_path = "RGB_file"
color_grp = f.require_group("color")
for scene in tqdm(os.listdir(color_file_path)):
print(scene)
scene_file_path = os.path.join(color_file_path, scene)
scene_grp = color_grp.require_group(scene)
for video in tqdm(os.listdir(scene_file_path)):
if video=="groundtruth":
continue
video_grp = scene_grp.require_group(video)
video_color_path = os.path.join(scene_file_path,video,"color")
for image in tqdm(os.listdir(video_color_path)):
img_path = os.path.join(video_color_path, image)
with open(img_path, 'rb') as img_f:
binary_data = img_f.read()
binary_data_np = np.asarray(binary_data)
dset = video_grp.create_dataset(f'{image[:-4]}', data=binary_data_np)
f.close()
|