Skip to content

Commit 0f125cb

Browse files
jakubcervenyJakub Červený
andauthored
Fix conversion from Blender to COLMAP coords in NeRF camera import. (#111)
Co-authored-by: Jakub Červený <[email protected]>
1 parent 073775e commit 0f125cb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scene/dataset_readers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,15 @@ def readCamerasFromTransforms(path, transformsfile, white_background, extension=
187187
for idx, frame in enumerate(frames):
188188
cam_name = os.path.join(path, frame["file_path"] + extension)
189189

190-
matrix = np.linalg.inv(np.array(frame["transform_matrix"]))
191-
R = -np.transpose(matrix[:3,:3])
192-
R[:,0] = -R[:,0]
193-
T = -matrix[:3, 3]
190+
# NeRF 'transform_matrix' is a camera-to-world transform
191+
c2w = np.array(frame["transform_matrix"])
192+
# change from OpenGL/Blender camera axes (Y up, Z back) to COLMAP (Y down, Z forward)
193+
c2w[:3, 1:3] *= -1
194+
195+
# get the world-to-camera transform and set R, T
196+
w2c = np.linalg.inv(c2w)
197+
R = np.transpose(w2c[:3,:3]) # R is stored transposed due to 'glm' in CUDA code
198+
T = w2c[:3, 3]
194199

195200
image_path = os.path.join(path, cam_name)
196201
image_name = Path(cam_name).stem

0 commit comments

Comments
 (0)