MCPcopy Index your code
hub / github.com/LeapLabTHU/ActiveNeRF / _load_data

Function _load_data

load_llff.py:62–118  ·  view source on GitHub ↗
(basedir, factor=None, width=None, height=None, load_imgs=True)

Source from the content-addressed store, hash-verified

60
61
62def _load_data(basedir, factor=None, width=None, height=None, load_imgs=True):
63
64 poses_arr = np.load(os.path.join(basedir, 'poses_bounds.npy'))
65 poses = poses_arr[:, :-2].reshape([-1, 3, 5]).transpose([1,2,0])
66 bds = poses_arr[:, -2:].transpose([1,0])
67
68 img0 = [os.path.join(basedir, 'images', f) for f in sorted(os.listdir(os.path.join(basedir, 'images'))) \
69 if f.endswith('JPG') or f.endswith('jpg') or f.endswith('png')][0]
70 sh = imageio.imread(img0).shape
71
72 sfx = ''
73
74 if factor is not None:
75 sfx = '_{}'.format(factor)
76 _minify(basedir, factors=[factor])
77 factor = factor
78 elif height is not None:
79 factor = sh[0] / float(height)
80 width = int(sh[1] / factor)
81 _minify(basedir, resolutions=[[height, width]])
82 sfx = '_{}x{}'.format(width, height)
83 elif width is not None:
84 factor = sh[1] / float(width)
85 height = int(sh[0] / factor)
86 _minify(basedir, resolutions=[[height, width]])
87 sfx = '_{}x{}'.format(width, height)
88 else:
89 factor = 1
90
91 imgdir = os.path.join(basedir, 'images' + sfx)
92 if not os.path.exists(imgdir):
93 print( imgdir, 'does not exist, returning' )
94 return
95
96 imgfiles = [os.path.join(imgdir, f) for f in sorted(os.listdir(imgdir)) if f.endswith('JPG') or f.endswith('jpg') or f.endswith('png')]
97 if poses.shape[-1] != len(imgfiles):
98 print( 'Mismatch between imgs {} and poses {} !!!!'.format(len(imgfiles), poses.shape[-1]) )
99 return
100
101 sh = imageio.imread(imgfiles[0]).shape
102 poses[:2, 4, :] = np.array(sh[:2]).reshape([2, 1])
103 poses[2, 4, :] = poses[2, 4, :] * 1./factor
104
105 if not load_imgs:
106 return poses, bds
107
108 def imread(f):
109 if f.endswith('png'):
110 return imageio.imread(f, ignoregamma=True)
111 else:
112 return imageio.imread(f)
113
114 imgs = imgs = [imread(f)[...,:3]/255. for f in imgfiles]
115 imgs = np.stack(imgs, -1)
116
117 print('Loaded image data', imgs.shape, poses[:,-1,0])
118 return poses, bds, imgs
119

Callers 1

load_llff_dataFunction · 0.85

Calls 2

_minifyFunction · 0.85
imreadFunction · 0.85

Tested by

no test coverage detected