python点云可视化

python点云可视化,第1张

Python三种点云可视化方案:mayavi、matplotlib、CloudCompare。


方案一:mayavi可视化点云

安装方式:

pip install mayavi

可视化代码:其中'airplane_0001.txt'数据下载地址为:modelnet40点云样例数据-深度学习文档类资源-CSDN下载

from mayavi import mlab
import numpy as np

def viz_mayavi(points):
    x = points[:, 0]  # x position of point
    y = points[:, 1]  # y position of point
    z = points[:, 2]  # z position of point
    fig = mlab.figure(bgcolor=(0, 0, 0), size=(640, 360)) #指定图片背景和尺寸
    mlab.points3d(x, y, z,
                         z,          # Values used for Color,指定颜色变化依据
                         mode="point",
                          colormap='spectral', # 'bone', 'copper', 'gnuplot'
                         # color=(0, 1, 0),   # 也可以使用固定的RGB值
                         )
    mlab.show()
points = np.loadtxt('airplane_0001.txt', delimiter=',')
viz_mayavi(points)

显示结果:

 方案

二、matplotlib可视化点云

代码如下所示:

import matplotlib.pyplot as plt
import numpy as np

def viz_matplot(points):
    x = points[:, 0]  # x position of point
    y = points[:, 1]  # y position of point
    z = points[:, 2]  # z position of point
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(x,   # x
               y,   # y
               z,   # z
               c=z, # height data for color
               cmap='rainbow',
               marker="x")
    ax.axis()
    plt.show()

    
points = np.loadtxt('airplane_0001.txt', delimiter=',')
viz_matplot(points)

显示结果:

 方案

三、CloudCompare可视化点云

直接用软件打开,无需安装。


CloudCompare下载地址:CloudCompare点云可视化软件-深度学习文档类资源-CSDN下载。


显示结果:

 Mayavi常用函数
from mayavi import mlab

fig = mlab.figure(bgcolor=(0, 0, 0), size=(640, 360)) #指定图片背景和尺寸

mlab.points3d(x, y, z,
              z,          # Values used for Color,指定颜色变化依据
              mode="point",
              colormap='spectral', # 'bone', 'copper', 'gnuplot'
              # color=(0, 1, 0),   # 也可以使用固定的RGB值
               )

opacity=1.0  # 不透明度,取值范围0-1。


0.0表示完全透明,1.0表示完全不透明 color=(1, 1, 1)  # RGB数值,每个数的取值范围均为0-1。


例:(1, 1, 1)表示白色。


colormap='spectral'  #  不同的配色方案 mlab.show()#显示结果 # 2D data img = xxxx # img is a 2D nunmpy array mlab.imshow(img) #显示二维结果 mlab.surf() mlab.contour_surf() mlab.mesh() #将物体表面以网格(mesh)的形式展示出来,即坐标空间的网格化。


# 参数:representation = 'wireframe' 可以仅绘制线框。


# 参数:representation = 'surface' 为default值,绘制完整曲面。


mlab.mesh(x, y, z, representation='wireframe', line_width=1.0 )

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/578786.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存