点云数据#
import dash
import dash_vtk
from dash import html, dcc
from dash.dependencies import Input, Output, State
import numpy as np
from pyvista import examples
np.random.seed(42)
# Get point cloud data from PyVista
dataset = examples.download_lidar()
subset = 0.2
selection = np.random.randint(
low=0, high=dataset.n_points - 1, size=int(dataset.n_points * subset)
)
points = dataset.points[selection]
xyz = points.ravel()
elevation = points[:, -1].ravel()
min_elevation = np.amin(elevation)
max_elevation = np.amax(elevation)
print(f"Number of points: {points.shape}")
print(f"Elevation range: [{min_elevation}, {max_elevation}]")
# Setup VTK rendering of PointCloud
app = dash.Dash(__name__)
server = app.server
vtk_view = dash_vtk.View(
[
dash_vtk.PointCloudRepresentation(
xyz=xyz,
scalars=elevation,
colorDataRange=[min_elevation, max_elevation],
property={"pointSize": 2},
)
]
)
app.layout = html.Div(
style={"height": "calc(100vh - 16px)"},
children=[html.Div(vtk_view, style={"height": "100%", "width": "100%"})],
)
if __name__ == "__main__":
app.run_server(debug=True, port=8891)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 7
4 from dash.dependencies import Input, Output, State
6 import numpy as np
----> 7 from pyvista import examples
9 np.random.seed(42)
11 # Get point cloud data from PyVista
ModuleNotFoundError: No module named 'pyvista'
也可以直接使用 open3d
加载 .ply
文件:
import numpy as np
import open3d
pcd = open3d.io.read_point_cloud("test.ply")
points = np.asarray(pcd.points)
xyz = points.ravel()
elevation = points[:, -1].ravel()
min_elevation = np.amin(elevation)
max_elevation = np.amax(elevation)
print(f"Number of points: {points.shape}")
print(f"Elevation range: [{min_elevation}, {max_elevation}]")
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 2
1 import numpy as np
----> 2 import open3d
4 pcd = open3d.io.read_point_cloud("test.ply")
5 points = np.asarray(pcd.points)
ModuleNotFoundError: No module named 'open3d'