ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

pclpy 均匀采样

2021-10-02 09:02:11  阅读:350  来源: 互联网

标签:采样 viewer 0.0 pclpy pcl 均匀 filtered cloud


均匀采样

一、算法原理

  均匀采样通过构建指定半径的球体对点云进行下采样滤波,将每一个球内距离球体中心最近的点作为下采样之后的点输出。

体素滤波(下采样)是建立一个立方体,均匀采样是建立一个球。

二、代码实现

from pclpy import pcl


def point_cloud_viewer(cloud, cloud_filtered):
    # Open 3D viewer and add point cloud and normals
    viewer = pcl.visualization.PCLVisualizer("cloud_viewer")
    v0 = 1
    viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v0)
    viewer.setBackgroundColor(0.0, 0.0, 0.0, v0)
    single_color = pcl.visualization.PointCloudColorHandlerCustom.PointXYZ(cloud, 0.0, 255.0, 0.0)
    viewer.addPointCloud(cloud, single_color, "sample cloud1", v0)

    v1 = 2
    viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v1)
    viewer.setBackgroundColor(0.0, 0.0, 0.0, v1)
    single_color = pcl.visualization.PointCloudColorHandlerCustom.PointXYZ(cloud_filtered, 255.0, 0.0, 0.0)
    viewer.addPointCloud(cloud_filtered, single_color, "sample cloud2", v1)

    viewer.setPointCloudRenderingProperties(0, 1, "sample cloud1", v0)
    viewer.setPointCloudRenderingProperties(0, 1, "sample cloud2", v1)
    # viewer.addCoordinateSystem(1.0)  # 显示坐标轴
    while not viewer.wasStopped():
        viewer.spinOnce(10)


if __name__ == '__main__':
    # 读取点云数据
    cloud = pcl.PointCloud.PointXYZ()
    cloud_filtered = pcl.PointCloud.PointXYZ()
    reader = pcl.io.PCDReader()
    reader.read('bunny.pcd', cloud)
    print("采样前点的个数为: ", cloud.size())

    # 创建均匀采样滤波器
    us = pcl.filters.UniformSampling.PointXYZ()
    us.setInputCloud(cloud)  # 输入点云
    us.setRadiusSearch(0.005)  # 设置滤波时创建的球体半径
    us.filter(cloud_filtered)
    print("均匀采样后点的个数为: ", cloud_filtered.size())

    # writer = pcl.io.PCDWriter()
    # writer.write("rs.pcd", cloud_filtered)
    # 可视化结果
    point_cloud_viewer(cloud, cloud_filtered)

三、结果展示

在这里插入图片描述

标签:采样,viewer,0.0,pclpy,pcl,均匀,filtered,cloud
来源: https://blog.csdn.net/qq_36686437/article/details/120575286

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有