From 4b78e95eeb2d83bd9c8b2f7a5c89e7e4346b7227 Mon Sep 17 00:00:00 2001 From: "guanming001@e.ntu.edu.sg" Date: Thu, 4 Jun 2020 04:03:37 -0700 Subject: [PATCH] Fixed look_at_rotation bug for 3 camera positions (#220) Summary: To address the issue https://github.com/facebookresearch/pytorch3d/issues/219 of Invalid rotation matrix when number of camera position is equal to 3 Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/220 Reviewed By: bottler Differential Revision: D21877606 Pulled By: nikhilaravi fbshipit-source-id: f95ae44497cae33f2f0cff1b1718d866cf79bda1 --- pytorch3d/renderer/cameras.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index 4f8fdbd7..f2de3d5a 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -916,8 +916,8 @@ def look_at_rotation( msg = "Expected arg %s to have shape (N, 3); got %r" raise ValueError(msg % (n, t.shape)) z_axis = F.normalize(at - camera_position, eps=1e-5) - x_axis = F.normalize(torch.cross(up, z_axis), eps=1e-5) - y_axis = F.normalize(torch.cross(z_axis, x_axis), eps=1e-5) + x_axis = F.normalize(torch.cross(up, z_axis, dim=1), eps=1e-5) + y_axis = F.normalize(torch.cross(z_axis, x_axis, dim=1), eps=1e-5) R = torch.cat((x_axis[:, None, :], y_axis[:, None, :], z_axis[:, None, :]), dim=1) return R.transpose(1, 2)