| 85 | frames = contents["frames"] |
| 86 | tbar = tqdm(range(len(frames))) |
| 87 | def frame_read_fn(idx_frame): |
| 88 | idx = idx_frame[0] # equals to image id? |
| 89 | frame = idx_frame[1] |
| 90 | timestamp = frame.get('time', 0.0) |
| 91 | cam_name = os.path.join(self.data_dir, frame.get('file_path', f'{idx:04d}') + extension) |
| 92 | |
| 93 | # NeRF 'transform_matrix' is a camera-to-world transform |
| 94 | c2w = np.array(frame["transform_matrix"]) |
| 95 | # change from OpenGL/Blender camera axes (Y up, Z back) to COLMAP (Y down, Z forward) |
| 96 | c2w[:3, 1:3] *= -1 |
| 97 | # get the world-to-camera transform and set R, T |
| 98 | w2c = np.linalg.inv(c2w) |
| 99 | R = np.transpose(w2c[:3,:3]) # R is stored transposed due to 'glm' in CUDA code |
| 100 | T = w2c[:3, 3] |
| 101 | |
| 102 | self.image_id.append(idx) |
| 103 | self.timestamp.append(timestamp) |
| 104 | self.c2w.append(c2w) |
| 105 | self.R.append(R) |
| 106 | self.T.append(T) |
| 107 | self.image.append(imageio.imread(cam_name)) |
| 108 | |
| 109 | tbar.update(1) |
| 110 | |
| 111 | with ThreadPool() as pool: |
| 112 | # pool.map(frame_read_fn, zip(list(range(len(frames))), frames)) |