python利用open3d以及mayavi可视化pcd点云(二进制)

pcd点云的存储形式一共有两种,分别是binary和ascll码的形式,其详解见https://blog.csdn.net/qq_37534947/article/details/107187907
下面的代码是针对两者的,即都可以适用。
前期准备:
open3d的安装
pip install open3d
pip install open3d-python==0.7.0.0 (这个必须有)
mayavi的安装:
需要顺序安装的包vtk、mayavi
这里推荐whl下载,因为pip直接安装vtk比较慢,下载地址:
https://download.csdn.net/download/qq_37534947/12515312

#binary
import open3d as o3d
import numpy as np
import numpy as np
import mayavi.mlab
def read_pcd(file_path1):
    pcd = o3d.io.read_point_cloud(file_path1)
    #pcd2 = o3d.io.read_point_cloud(file_path2)
    print(np.asarray(pcd.points))
    #print(np.asarray(pcd2.points))
    #colors = np.asarray(pcd.colors) * 255
    pointcloud = np.asarray(pcd.points)
    #pointcloud2 = np.asarray(pcd2.points)
    print(pointcloud.shape)
    #print(pointcloud2.shape)
    x = pointcloud[:, 0]  # x position of point
    xmin = np.amin(x, axis=0)
    xmax = np.amax(x, axis=0 )
    y = pointcloud[:, 1]  # y position of point
    ymin = np.amin(y, axis=0)
    ymax = np.amax(y, axis=0)
    z = pointcloud[:, 2]  # z position of point
    zmin = np.amin(z, axis=0)
    zmax = np.amax(z, axis=0)
    print(xmin,xmax,ymin,ymax,zmin,zmax)
    d = np.sqrt(x ** 2 + y ** 2)  # Map Distance from sensor
    vals = 'height'
    if vals == "height":
        col = z
    else:
        col = d
    fig = mayavi.mlab.figure(bgcolor=(0, 0, 0), size=(640, 500))
    mayavi.mlab.points3d(x, y, z,
                         col,  # Values used for Color
                         mode="point",
                         # 灰度图的伪彩映射
                         colormap='spectral',  # 'bone', 'copper', 'gnuplot'
                         # color=(0, 1, 0),   # Used a fixed (r,g,b) instead
                         figure=fig,
                         )
    # 绘制原点
    mayavi.mlab.points3d(0, 0, 0, color=(1, 1, 1), mode="sphere",scale_factor=0.2)
    # 绘制坐标
    axes = np.array(
        [[20.0, 0.0, 0.0, 0.0], [0.0, 20.0, 0.0, 0.0], [0.0, 0.0, 20.0, 0.0]],
        dtype=np.float64,
    )
    #x轴
    mayavi.mlab.plot3d(
        [0, axes[0, 0]],
        [0, axes[0, 1]],
        [0, axes[0, 2]],
        color=(1, 0, 0),
        tube_radius=None,
        figure=fig,
    )
    #y轴
    mayavi.mlab.plot3d(
        [0, axes[1, 0]],
        [0, axes[1, 1]],
        [0, axes[1, 2]],
        color=(0, 1, 0),
        tube_radius=None,
        figure=fig,
    )
    #z轴
    mayavi.mlab.plot3d(
        [0, axes[2, 0]],
        [0, axes[2, 1]],
        [0, axes[2, 2]],
        color=(0, 0, 1),
        tube_radius=None,
        figure=fig,
    )
    mayavi.mlab.show()

#mayavi显示点云
read_pcd("pcdfolder/Benewake_Horn_X2_PointCloud_0023.pcd")#,"pcdfolder/Benewake_Horn_X2_PointCloud_0001.pcd")

分析:
1)这里open3d的主要作用是打开pcd格式的文件,然后存储到pcd 变量中,可以从shape中看到其大小是(x,3),其中x是指点云的个数。
2)mayavi主要是用于显示点云,其中包括显示所有的点以及绘制横坐标以及纵坐标和绘制原点等。
其使用参考链接:
https://www.cnblogs.com/dalanjing/p/12289517.html
https://www.cnblogs.com/ssyfj/p/9303698.html

结果截图:
在这里插入图片描述

  • 6
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Studying_swz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值