SPIN icon indicating copy to clipboard operation
SPIN copied to clipboard

compute 6D rotation representation from rotation matrix or quaternion

Open luguansong opened this issue 4 years ago • 2 comments

Thanks a lot for your code. Do you know how to compute 6D rotation representation from rotation matrix or quaternion?

luguansong avatar Apr 06 '20 09:04 luguansong

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).

akashsengupta1997 avatar Apr 06 '20 14:04 akashsengupta1997

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?

luguansong avatar Apr 06 '20 15:04 luguansong