Skip to content

Commit

Permalink
ct.project.homo_project -> ct.transform.transform_points
Browse files Browse the repository at this point in the history
  • Loading branch information
yxlao committed Oct 22, 2023
1 parent 3871b62 commit 19534ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion camtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from . import metric
from . import normalize
from . import plot
from . import project
from . import transform
from . import raycast
from . import sanity
from . import solver
Expand Down
20 changes: 15 additions & 5 deletions camtools/project.py → camtools/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@
from . import convert


def homo_project(points, mat):
def transform_points(points, transform_mat):
"""
Transform points by a 4x4 matrix via homogenous coordinates projection.
Args:
points: (N, 3) array.
mat: (4, 4) array, the transformation matrix.
Returns:
(N, 3) array, the transformed points.
"""
sanity.assert_shape_nx3(points, name="points")
sanity.assert_shape_4x4(mat, name="mat")
sanity.assert_same_device(points, mat)
sanity.assert_shape_4x4(transform_mat, name="mat")
sanity.assert_same_device(points, transform_mat)

N = len(points)
if torch.is_tensor(mat):
if torch.is_tensor(transform_mat):
ones = torch.ones((N, 1), dtype=points.dtype, device=points.device)
points_homo = torch.hstack((points, ones))
else:
ones = np.ones((N, 1))
points_homo = np.hstack((points, ones))

# (mat @ points_homo.T).T
points_out = points_homo @ mat.T
points_out = points_homo @ transform_mat.T
points_out = points_out[:, :3] / points_out[:, 3:]
return points_out

Expand Down

0 comments on commit 19534ca

Please sign in to comment.