MCPcopy Index your code
hub / github.com/DNA-Rendering/DNA-Rendering / readCamerasFromTransforms

Function readCamerasFromTransforms

scripts/3DGS/dataset_readers.py:189–229  ·  view source on GitHub ↗
(path, transformsfile, white_background, extension=".png")

Source from the content-addressed store, hash-verified

187 return scene_info
188
189def readCamerasFromTransforms(path, transformsfile, white_background, extension=".png"):
190 cam_infos = []
191
192 with open(os.path.join(path, transformsfile)) as json_file:
193 contents = json.load(json_file)
194 fovx = contents["camera_angle_x"]
195
196 frames = contents["frames"]
197 for idx, frame in enumerate(frames):
198 cam_name = os.path.join(path, frame["file_path"] + extension)
199
200 # NeRF 'transform_matrix' is a camera-to-world transform
201 c2w = np.array(frame["transform_matrix"])
202 # change from OpenGL/Blender camera axes (Y up, Z back) to COLMAP (Y down, Z forward)
203 c2w[:3, 1:3] *= -1
204
205 # get the world-to-camera transform and set R, T
206 w2c = np.linalg.inv(c2w)
207 R = np.transpose(w2c[:3,:3]) # R is stored transposed due to 'glm' in CUDA code
208 T = w2c[:3, 3]
209
210 image_path = os.path.join(path, cam_name)
211 image_name = Path(cam_name).stem
212 image = Image.open(image_path)
213
214 im_data = np.array(image.convert("RGBA"))
215
216 bg = np.array([1,1,1]) if white_background else np.array([0, 0, 0])
217
218 norm_data = im_data / 255.0
219 arr = norm_data[:,:,:3] * norm_data[:, :, 3:4] + bg * (1 - norm_data[:, :, 3:4])
220 image = Image.fromarray(np.array(arr*255.0, dtype=np.byte), "RGB")
221
222 fovy = focal2fov(fov2focal(fovx, image.size[0]), image.size[1])
223 FovY = fovy
224 FovX = fovx
225
226 cam_infos.append(CameraInfo(uid=idx, R=R, T=T, FovY=FovY, FovX=FovX, image=image,
227 image_path=image_path, image_name=image_name, width=image.size[0], height=image.size[1]))
228
229 return cam_infos
230
231def readNerfSyntheticInfo(path, white_background, eval, extension=".png"):
232 print("Reading Training Transforms")

Callers 1

readNerfSyntheticInfoFunction · 0.85

Calls 3

focal2fovFunction · 0.90
fov2focalFunction · 0.90
CameraInfoClass · 0.85

Tested by

no test coverage detected