Skip to content

Commit

Permalink
Fix conversion from Blender to COLMAP coords in NeRF camera import. (g…
Browse files Browse the repository at this point in the history
…raphdeco-inria#111)

Co-authored-by: Jakub Červený <jakub.cerveny@melowntech.com>
  • Loading branch information
jakubcerveny and Jakub Červený authored Aug 24, 2023
1 parent 073775e commit 0f125cb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scene/dataset_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ def readCamerasFromTransforms(path, transformsfile, white_background, extension=
for idx, frame in enumerate(frames):
cam_name = os.path.join(path, frame["file_path"] + extension)

matrix = np.linalg.inv(np.array(frame["transform_matrix"]))
R = -np.transpose(matrix[:3,:3])
R[:,0] = -R[:,0]
T = -matrix[:3, 3]
# NeRF 'transform_matrix' is a camera-to-world transform
c2w = np.array(frame["transform_matrix"])
# change from OpenGL/Blender camera axes (Y up, Z back) to COLMAP (Y down, Z forward)
c2w[:3, 1:3] *= -1

# get the world-to-camera transform and set R, T
w2c = np.linalg.inv(c2w)
R = np.transpose(w2c[:3,:3]) # R is stored transposed due to 'glm' in CUDA code
T = w2c[:3, 3]

image_path = os.path.join(path, cam_name)
image_name = Path(cam_name).stem
Expand Down

0 comments on commit 0f125cb

Please sign in to comment.