instant-ngp-Windows icon indicating copy to clipboard operation
instant-ngp-Windows copied to clipboard

How can I convert transformation matrix from transforms.json to base_cam.json format?

Open wooni-github opened this issue 1 year ago • 0 comments

Hi.

I'd like to render an image with exact same pose from transforms.json file using render.py.

For example, datan/nerf/fox/, first image images/0001.jpg has transform matrix as below.

      "transform_matrix": [
    [
      0.8926439112348871,
      0.08799600283226543,
      0.4420900262071262,
      3.168359405609479
    ],
    [
      0.4464189982715247,
      -0.03675452191179031,
      -0.8940689141475064,
      -5.4794898611466945
    ],
    [
      -0.062425682580756266,
      0.995442519072023,
      -0.07209178487538156,
      -0.9791660699008925
    ],
    [
      0.0,
      0.0,
      0.0,
      1.0
    ]

Here, I have to convert it to quaternion & translation to use it as base_cam.json format

for example, ...

"R":[0.8109075427055359,0.03559545800089836,0.5819807648658752,-0.04959719628095627],
"T": -2.2435450553894043,0.11715501546859741,1.4327683448791504],"dof":0.0,"fov":50.625,"scale":2.9230759143829346,"slice":0.03611110895872116

I tried to convert it using code below, the result does not match to what I want. Am I missing something?

import numpy as np
from scipy.spatial.transform import Rotation as R

T = np.array(
[[
	0.8926439112348871,
	0.08799600283226543,
	0.4420900262071262,
	3.168359405609479
],
[
	0.4464189982715247,
	-0.03675452191179031,
	-0.8940689141475064,
	-5.4794898611466945
],
[
	-0.062425682580756266,
	0.995442519072023,
	-0.07209178487538156,
	-0.9791660699008925
]]
)

# Extract rotation matrix (R) and translation vector (t)
R_mat = T[:3, :3]
t = T[:3, 3]

# Convert the rotation matrix to a quaternion
rot = R.from_matrix(R_mat)
q = rot.as_quat()

wooni-github avatar Mar 18 '23 09:03 wooni-github