gpt4 book ai didi

python - 过滤点云

转载 作者:行者123 更新时间:2023-12-05 06:49:39 42 4
gpt4 key购买 nike

我希望尽可能高效地过滤加载有 opend3d 的点云。

目前,我先对点进行下采样,然后再用它们制作网格,然后在我手动创建的包含体网格上使用 .contains。像这样:

    def load_pointcloud(self, pointcloud_path): 
# Load Pointcloud
print('target_pointcloud', pointcloud_path)
self.pointcloud_path = pointcloud_path

pcd = o3d.io.read_point_cloud(pointcloud_path)
downpcd = pcd.voxel_down_sample(voxel_size=0.02)
cl, ind = downpcd.remove_statistical_outlier(nb_neighbors=20,
std_ratio=2.0)
downpcd = downpcd.select_by_index(ind)
pcd_points = np.asarray(downpcd.points, dtype=np.float32)

self.verts = torch.from_numpy(pcd_points)
self.verts = self.verts.to(device)

# We construct a Meshes structure for the target mesh
self.pointcloud_points = Pointclouds(points=[self.verts])
self.points = pcd_points
self.inclusion_pointcloud()

def inclusion_pointcloud(self):
vetices_in_mesh_states = self.mesh_inclusion.contains(self.points)
vetices_in_mesh = self.points[vetices_in_mesh_states == True]

# Creating cropped point cloud
cropped_pc = o3d.geometry.PointCloud()
cropped_pc.points = o3d.utility.Vector3dVector(vetices_in_mesh)
cropped_pc.paint_uniform_color([0,0,0])

self.points = np.asarray(cropped_pc.points, dtype=np.float32)
self.verts = torch.from_numpy(self.points)
self.verts = self.verts.to(device)
self.pointcloud_points = Pointclouds(points=[self.verts])
self.pc_mesh = trimesh.Trimesh(vertices=self.points)

我想做的是,在下采样之后,屏蔽掉 X、Y 和 Z 上的点,然后制作一个网格以在同一包含体积中再次使用 .contains。我认为这会减少 .contains 计算并运行得更快,确实如此,但只是边际减少,例如 10 或 15 毫秒,有时甚至更少。像这样:

    def new_load_pointcloud(self, pointcloud_path): 
# Load Pointcloud
print('target_pointcloud', pointcloud_path)
self.pointcloud_path = pointcloud_path

pcd = self.trim_cloud(pointcloud_path)
downpcd = pcd.voxel_down_sample(voxel_size=0.02)
cl, ind = downpcd.remove_statistical_outlier(nb_neighbors=20,
std_ratio=2.0)
downpcd = downpcd.select_by_index(ind)
pcd_points = np.asarray(downpcd.points, dtype=np.float32)

self.verts = torch.from_numpy(pcd_points)
self.verts = self.verts.to(device)

# We construct a Meshes structure for the target mesh
self.pointcloud_points = Pointclouds(points=[self.verts])
self.points = pcd_points
self.inclusion_pointcloud()

def trim_cloud(self, pointcloud_path):
# pcd = o3d.io.read_point_cloud(pointcloud_path)
pcd_clean = o3d.io.read_point_cloud(pointcloud_path)

# X Axis
points = np.asarray(pcd_clean.points)
mask_x_1 = points[:,0] > -0.4
mask_x_2 = points[:,0] < 0.4

# Y Axis
mask_y_1 = points[:,1] > -1.3
mask_y_2 = points[:,1] < 0.9

# Z Axis
mask_z_1 = points[:,2] < 0.3 # Closer to floor
mask_z_2 = points[:,2] > -0.1 # Clooser to ceiling

mask_x = np.logical_and(mask_x_1, mask_x_2) # Along table's wide
mask_y = np.logical_and(mask_y_1, mask_y_2) # Along table's longitude
mask_z = np.logical_and(mask_z_1, mask_z_2) # Along table's height
mask = np.logical_and(mask_x, mask_y, mask_z)
pcd_clean.points = o3d.utility.Vector3dVector(points[mask])

return pcd_clean

def inclusion_pointcloud(self):
vetices_in_mesh_states = self.mesh_inclusion.contains(self.points)
vetices_in_mesh = self.points[vetices_in_mesh_states == True]

# Creating cropped point cloud
cropped_pc = o3d.geometry.PointCloud()
cropped_pc.points = o3d.utility.Vector3dVector(vetices_in_mesh)
cropped_pc.paint_uniform_color([0,0,0])

self.points = np.asarray(cropped_pc.points, dtype=np.float32)
self.verts = torch.from_numpy(self.points)
self.verts = self.verts.to(device)
self.pointcloud_points = Pointclouds(points=[self.verts])
self.pc_mesh = trimesh.Trimesh(vertices=self.points)

最佳答案

我认为您在过滤器中使用了过多的 nb_neighbors。尝试更少的分数,例如 6 或 10,以及更好的阈值,例如 1.0 甚至 0.5。这是 MATLAB 文档中的相同过滤器 https://www.mathworks.com/help/vision/ref/pcdenoise.html ,阈值的标准值为 1.0,knn 的标准值为 6。您也可以尝试使用半径离群值去除或中值过滤器:https://www.mathworks.com/help/lidar/ref/pcmedian.html

关于python - 过滤点云,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66574276/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com