-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): add points_to_depths function to calculate z-depths
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import numpy as np | ||
import open3d as o3d | ||
|
||
import camtools as ct | ||
|
||
|
||
def test_points_to_depths(visualize=True): | ||
# Identity camera pose (looking at +Z axis) | ||
T = np.eye(4) | ||
fx = fy = 500 | ||
cx = 320 | ||
cy = 240 | ||
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]]) | ||
|
||
# Create points on a plane z units away from origin | ||
num_points = 1000 | ||
z = 3.0 | ||
x = np.random.uniform(-4, 4, num_points) | ||
y = np.random.uniform(-4, 4, num_points) | ||
points = np.column_stack([x, y, np.full(num_points, z)]) | ||
|
||
# Test depths are all close to z | ||
depths = ct.project.points_to_depths(points, T) | ||
assert np.allclose( | ||
depths, z | ||
), f"Depths should be {z}, got {depths.min():.2f}-{depths.max():.2f}" | ||
|
||
if visualize: | ||
pcd = o3d.geometry.PointCloud() | ||
pcd.points = o3d.utility.Vector3dVector(points) | ||
pcd.paint_uniform_color([1, 0, 0]) # Red points | ||
frustum = ct.camera.create_camera_frustums( | ||
Ks=[K], | ||
Ts=[T], | ||
size=1.0, | ||
) | ||
axes = o3d.geometry.TriangleMesh.create_coordinate_frame(size=1) | ||
o3d.visualization.draw_geometries([pcd, frustum, axes]) |