From 110d085d1a306aee351870dbddf229ea26c8777d Mon Sep 17 00:00:00 2001 From: Kevin Chen <79341521+kevinddchen@users.noreply.github.com> Date: Tue, 8 Nov 2022 19:58:17 +0000 Subject: [PATCH] Use focal length --- nerfstudio/cameras/cameras.py | 7 +++---- scripts/process_data.py | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/nerfstudio/cameras/cameras.py b/nerfstudio/cameras/cameras.py index ec9649343..5ca53881f 100644 --- a/nerfstudio/cameras/cameras.py +++ b/nerfstudio/cameras/cameras.py @@ -315,10 +315,9 @@ class Cameras: dim=-1, ) elif self.camera_type[0] == CameraType.EQUIRECTANGULAR.value: - # u goes from -w/2 to w/2 - # v goes from -h/2 to h/2 - phi = torch.pi * (0.5 - coord_stack[..., 1] / self.image_height[camera_indices]) - theta = -2 * torch.pi * coord_stack[..., 0] / self.image_width[camera_indices] + # u and v go from -1/2 to 1/2 + phi = torch.pi * (0.5 - coord_stack[..., 1]) + theta = -2 * torch.pi * coord_stack[..., 0] # use spherical in local camera coordinates (+y up, x=0 and z<0 is theta=0) directions_stack = torch.stack( [-torch.sin(theta) * torch.sin(phi), torch.cos(phi), -torch.cos(theta) * torch.sin(phi)], diff --git a/scripts/process_data.py b/scripts/process_data.py index 3d26dc471..dd572fcd8 100755 --- a/scripts/process_data.py +++ b/scripts/process_data.py @@ -605,8 +605,8 @@ def opensfm_to_json(reconstruction_path: Path, output_dir: Path, camera_model: C # For now just assume it's all the same camera cam = cams[list(cams.keys())[0]] out = { - "fl_x": float(cam["focal_x"]) if "focal_x" in cam else 1.0, - "fl_y": float(cam["focal_y"]) if "focal_y" in cam else 1.0, + "fl_x": float(cam["focal_x"]) if "focal_x" in cam else float(cam["width"]), + "fl_y": float(cam["focal_y"]) if "focal_y" in cam else float(cam["height"]), "cx": float(cam["c_x"]) if "c_x" in cam else 0.5 * cam["width"], "cy": float(cam["c_y"]) if "c_y" in cam else 0.5 * cam["height"], "w": int(cam["width"]),