-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix holes and performance * expose confidence maps * start for point cloud tutorial * new PointCloud type * finish pointcloud tutorial * switch to open3d tensor api * fix mypy issues * disable testing for point cloud notebooks * set timeout back to 300 * tests for crop_point_cloud() * update rerun point cloud logging * rename pointcloud to point_cloud * point cloud spelling * fix notebooks * update changelog
- Loading branch information
1 parent
1a3425e
commit f4675a1
Showing
21 changed files
with
1,525 additions
and
73 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
airo_camera_toolkit/image_transforms/tutorial_image.jpg | ||
airo_camera_toolkit/calibration/saved_calibrations | ||
**/calibration_20**/ | ||
notebooks/data |
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
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
Empty file.
52 changes: 52 additions & 0 deletions
52
airo-camera-toolkit/airo_camera_toolkit/point_clouds/conversions.py
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,52 @@ | ||
from typing import Any | ||
|
||
import open3d as o3d | ||
import open3d.core as o3c | ||
from airo_typing import PointCloud | ||
|
||
|
||
def point_cloud_to_open3d(point_cloud: PointCloud) -> Any: # TODO: change Any back to o3d.t.geometry.PointCloud | ||
"""Converts a PointCloud dataclass object to an open3d tensor point cloud. | ||
Note that the memory buffers of the underlying numpy arrays are shared between the two. | ||
Args: | ||
point_cloud: the point cloud to convert | ||
Returns: | ||
pcd: the open3d tensor point cloud | ||
""" | ||
positions = o3c.Tensor.from_numpy(point_cloud.points) | ||
|
||
map_to_tensors = { | ||
"positions": positions, | ||
} | ||
|
||
if point_cloud.colors is not None: | ||
colors = o3c.Tensor.from_numpy(point_cloud.colors) | ||
map_to_tensors["colors"] = colors | ||
|
||
if point_cloud.attributes is not None: | ||
for attribute_name, array in point_cloud.attributes.items(): | ||
map_to_tensors[attribute_name] = o3c.Tensor.from_numpy(array) | ||
|
||
pcd = o3d.t.geometry.PointCloud(map_to_tensors) | ||
return pcd | ||
|
||
|
||
def open3d_to_point_cloud(pcd: Any) -> PointCloud: # TODO: change Any back to o3d.t.geometry.PointCloud | ||
"""Converts an open3d point cloud to a PointCloud dataclass object. | ||
Note that the memory buffers of the underlying numpy arrays are shared between the two. | ||
Args: | ||
pcd: the open3d tensor point cloud | ||
""" | ||
points = pcd.point.positions.numpy() | ||
colors = pcd.point.colors.numpy() if "colors" in pcd.point else None | ||
|
||
attributes = {} | ||
for attribute_name, array in pcd.point.items(): | ||
if attribute_name in ["positions", "colors"]: | ||
continue | ||
attributes[attribute_name] = array.numpy() | ||
|
||
return PointCloud(points, colors) |
63 changes: 63 additions & 0 deletions
63
airo-camera-toolkit/airo_camera_toolkit/point_clouds/operations.py
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,63 @@ | ||
from typing import Any | ||
|
||
import numpy as np | ||
from airo_typing import BoundingBox3DType, PointCloud | ||
|
||
|
||
def filter_point_cloud(point_cloud: PointCloud, mask: Any) -> PointCloud: | ||
"""Creates a new point cloud that is filtered by the given mask. | ||
Will also filter the colors and attributes if they are present. | ||
Args: | ||
point_cloud: the point cloud to filter | ||
mask: the mask to filter the point cloud by, used to index the attribute arrays, can be boolean or indices | ||
Returns: | ||
the new filtered point cloud | ||
""" | ||
points = point_cloud.points[mask] | ||
colors = None if point_cloud.colors is None else point_cloud.colors[mask] | ||
|
||
attributes = None | ||
if point_cloud.attributes is not None: | ||
attributes = {} | ||
for key, value in point_cloud.attributes.items(): | ||
attributes[key] = value[mask] | ||
|
||
point_cloud_filtered = PointCloud(points, colors, attributes) | ||
return point_cloud_filtered | ||
|
||
|
||
def generate_point_cloud_crop_mask(point_cloud: PointCloud, bounding_box: BoundingBox3DType) -> np.ndarray: | ||
"""Creates a mask that can be used to filter a point cloud to the given bounding box. | ||
Args: | ||
bounding_box: the bounding box that surrounds the points to keep | ||
point_cloud: the point cloud to crop | ||
Returns: | ||
the mask that can be used to filter the point cloud | ||
""" | ||
points = point_cloud.points | ||
x, y, z = points[:, 0], points[:, 1], points[:, 2] | ||
(x_min, y_min, z_min), (x_max, y_max, z_max) = bounding_box | ||
crop_mask = (x >= x_min) & (x <= x_max) & (y >= y_min) & (y <= y_max) & (z >= z_min) & (z <= z_max) | ||
return crop_mask | ||
|
||
|
||
def crop_point_cloud( | ||
point_cloud: PointCloud, | ||
bounding_box: BoundingBox3DType, | ||
) -> PointCloud: | ||
"""Creates a new point cloud that is cropped to the given bounding box. | ||
Will also crop the colors and attributes if they are present. | ||
Args: | ||
bounding_box: the bounding box that surrounds the points to keep | ||
point_cloud: the point cloud to crop | ||
Returns: | ||
the new cropped point cloud | ||
""" | ||
crop_mask = generate_point_cloud_crop_mask(point_cloud, bounding_box) | ||
return filter_point_cloud(point_cloud, crop_mask.nonzero()) |
24 changes: 24 additions & 0 deletions
24
airo-camera-toolkit/airo_camera_toolkit/point_clouds/visualization.py
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,24 @@ | ||
from typing import Any, Tuple | ||
|
||
import open3d as o3d | ||
from airo_typing import Vector3DType | ||
|
||
|
||
def open3d_point( | ||
position: Vector3DType, color: Tuple[float, float, float], radius: float = 0.01 | ||
) -> Any: # Change Any back to o3d.geometry.TriangleMesh | ||
"""Creates a small sphere mesh for visualization in open3d. | ||
Args: | ||
position: 3D position of the point | ||
color: RGB color of the point as 0-1 floats | ||
radius: radius of the sphere | ||
Returns: | ||
sphere: an open3d mesh | ||
""" | ||
sphere = o3d.geometry.TriangleMesh.create_sphere(radius=radius) | ||
sphere.translate(position) | ||
sphere.paint_uniform_color(color) | ||
sphere.compute_vertex_normals() | ||
return sphere |
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
Oops, something went wrong.