30 lines
1.1 KiB
Python
Raw Normal View History

2024-09-19 13:26:58 -05:00
import numpy as np
import open3d as o3d
2024-09-23 15:33:12 +08:00
import torch
2024-09-19 13:26:58 -05:00
class PtsUtil:
@staticmethod
def voxel_downsample_point_cloud(point_cloud, voxel_size=0.005):
o3d_pc = o3d.geometry.PointCloud()
o3d_pc.points = o3d.utility.Vector3dVector(point_cloud)
downsampled_pc = o3d_pc.voxel_down_sample(voxel_size)
return np.asarray(downsampled_pc.points)
@staticmethod
def transform_point_cloud(points, pose_mat):
points_h = np.concatenate([points, np.ones((points.shape[0], 1))], axis=1)
points_h = np.dot(pose_mat, points_h.T).T
return points_h[:, :3]
@staticmethod
def random_downsample_point_cloud(point_cloud, num_points):
2024-10-01 14:51:45 +08:00
if point_cloud.shape[0] == 0:
return point_cloud
2024-09-23 15:33:12 +08:00
idx = np.random.choice(len(point_cloud), num_points, replace=True)
return point_cloud[idx]
@staticmethod
def random_downsample_point_cloud_tensor(point_cloud, num_points):
idx = torch.randint(0, len(point_cloud), (num_points,))
2024-09-19 13:26:58 -05:00
return point_cloud[idx]