MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / get_tensor_from_camera

Function get_tensor_from_camera

utils/pose_utils.py:183–215  ·  view source on GitHub ↗

Convert transformation matrix to quaternion and translation.

(RT, Tquad=False)

Source from the content-addressed store, hash-verified

181
182
183def get_tensor_from_camera(RT, Tquad=False):
184 """
185 Convert transformation matrix to quaternion and translation.
186
187 """
188 # gpu_id = -1
189 # if type(RT) == torch.Tensor:
190 # if RT.get_device() != -1:
191 # gpu_id = RT.get_device()
192 # RT = RT.detach().cpu()
193 # RT = RT.numpy()
194 # from mathutils import Matrix
195 #
196 # R, T = RT[:3, :3], RT[:3, 3]
197 # rot = Matrix(R)
198 # quad = rot.to_quaternion()
199 # if Tquad:
200 # tensor = np.concatenate([T, quad], 0)
201 # else:
202 # tensor = np.concatenate([quad, T], 0)
203 # tensor = torch.from_numpy(tensor).float()
204 # if gpu_id != -1:
205 # tensor = tensor.to(gpu_id)
206 # return tensor
207
208 if not isinstance(RT, torch.Tensor):
209 RT = torch.tensor(RT).cuda()
210
211 rot = RT[:3, :3].unsqueeze(0).detach()
212 quat = rotation2quad(rot).squeeze()
213 tran = RT[:3, 3].detach()
214
215 return torch.cat([quat, tran])
216
217def normalize(x):
218 return x / np.linalg.norm(x)

Callers 3

render_setFunction · 0.90
render_set_optimizeFunction · 0.90
init_RT_seqMethod · 0.90

Calls 1

rotation2quadFunction · 0.85

Tested by

no test coverage detected