-
Notifications
You must be signed in to change notification settings - Fork 9
/
add_more_data.py
46 lines (37 loc) · 1.58 KB
/
add_more_data.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
import h5py
import os, sys, traceback
import os.path as osp
import wget, tarfile
import cv2
def add_more_data_into_dset(DB_FNAME,more_img_file_path,more_depth_path,more_seg_path):
db=h5py.File(DB_FNAME,'wb+')
depth_db=get_data(more_depth_path)
seg_db=get_data(more_seg_path)
db.create_group('image')
db.create_group('depth')
db.create_group('seg')
for imname in os.listdir(more_img_file_path):
if imname.endswith('.jpg'):
full_path=more_img_file_path+imname
print(full_path,imname)
j=Image.open(full_path)
imgSize=j.size
rawData=j.tostring()
img=Image.fromstring('RGB',imgSize,rawData)
#img = img.astype('uint16')
db['image'].create_dataset(imname,data=img)
db['depth'].create_dataset(imname,data=depth_db[imname])
db['seg'].create_dataset(imname,data=seg_db['mask'][imname])
db['seg'][imname].attrs['area']=seg_db['mask'][imname].attrs['area']
db['seg'][imname].attrs['label']=seg_db['mask'][imname].attrs['label']
db.close()
depth_db.close()
seg_db.close()
# path to the data-file, containing image, depth and segmentation:
DB_FNAME = '/home/yuz/lijiahui/syntheticdata/SynthText/more_data_from_off/dset_8000.h5'
#add more data into the dset
more_depth_path='/home/yuz/lijiahui/syntheticdata/SynthText/more_data_from_off/depth.h5'
more_seg_path='/home/yuz/lijiahui/syntheticdata/SynthText/more_data_from_off/seg.h5'
more_img_file_path='/home/yuz/lijiahui/syntheticdata/SynthText/more_data_from_off/bg_img/'
add_more_data_into_dset(DB_FNAME,more_img_file_path,more_depth_path,more_seg_path)