SPIN
SPIN copied to clipboard
compute 6D rotation representation from rotation matrix or quaternion
Thanks a lot for your code. Do you know how to compute 6D rotation representation from rotation matrix or quaternion?
To go from a rotation matrix to the 6D representation, I believe you simply take the first two columns of the 3x3 rotation matrix (and concatenate them together if needed).
Thanks for your reply. Here is my implementation:
from utils.geometry import batch_rodrigues, rot6d_to_rotmat
import torch
def rotmat_to_rot6d(x):
a1 = x[:, :, 0]
a2 = x[:, :, 1]
# first one
return torch.cat([a1, a2], dim=-1)
# second one
# return x[:, :, :2].reshape(-1 ,6)
if __name__ == "__main__":
angles = torch.Tensor([[0, 0, 0], [1, 1, 1], [2, 2, 2]])
rotmat_batch_rodrigues = batch_rodrigues(angles)
rot6d = rotmat_to_rot6d(rotmat_batch_rodrigues)
rotmat_recon = rot6d_to_rotmat(rot6d)
print(rotmat_batch_rodrigues)
print(rotmat_recon)
I tried two kinds of concatenation, but the results of rotmat_batch_rodrigues and rotmat_recon are not the same. Anything wrong here?