Open3d计算点云之间距离

compute_point_cloud_distance函数计算从源点云中每个点到目标点云中最近邻点的距离。

dists=src.compute_point_cloud_distance(target)

参数
src: the source point cloud
target: the target point cloud
返回值:
dists:源点云中每个点到目标点云中最近邻点的距离


import open3d as o3d
import numpy as np

if __name__ == "__main__":
    sample_ply_data = o3d.data.DemoCropPointCloud()
    pcd = o3d.io.read_point_cloud(sample_ply_data.point_cloud_path)

    vol = o3d.visualization.read_selection_polygon_volume(
        sample_ply_data.cropped_json_path)
    chair = vol.crop_point_cloud(pcd)
	
    chair.paint_uniform_color([0, 0, 1])
    pcd.paint_uniform_color([1, 0, 0])
    print("Displaying the two point clouds used for calculating distance ...")
    o3d.visualization.draw([pcd, chair])

    dists = pcd.compute_point_cloud_distance(chair)
    dists = np.asarray(dists)
    print("Printing average distance between the two point clouds ...")
    print(dists)

从json文件读取一个指定的多边形区域

open3d.visualization.read_selection_polygon_volume(filename)

去掉点云pcd在多边形区域外的点,也就是对点云进行裁剪

 chair = vol.crop_point_cloud(pcd)

下面是一段非常实用的计算点云之间差异并可视化的代码。

import open3d as o3d
import numpy as np
pc_src = o3d.io.read_point_cloud("data/1.ply",remove_nan_points=True,remove_infinite_points=True)
pc_dst = o3d.io.read_point_cloud("data/2.ply",remove_nan_points=True,remove_infinite_points=True)
dist = pc_dst.compute_point_cloud_distance(pc_src )
idx = [i for i,distance in enumerate(dist)  if distance<0.5 ]

same_part = pc_dst.select_by_index(idx)
diff_part = pc_dst.select_by_index(idx,invert=True)
same_part.paint_uniform_color([0,0,1])
diff_part.paint_uniform_color([1,0,0])
o3d.visualization.draw_geometries([same_part,diff_part])

按照索引从输入点云中选取部分点。

pcd_out=pcd.select_by_index(self, indices, invert=False)
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值