Python读取/处理/可视化激光点云【LiDAR】
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span> 3D 点云数据<span style="color: black;">拥有</span>挑战性。 一张激光雷达图像中的点集合<span style="color: black;">一般</span>很广泛,<span style="color: black;">按照</span>图像<span style="color: black;">体积</span>可能达到数百万个点。 处理高度维度还带来了其他<span style="color: black;">繁杂</span>性。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/95311be090b74c0280bfecd6e538d1e2~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728805476&x-signature=Lktiyc63prmgFRc8LM3L%2Bw1AeNM%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">举荐</span>:用 NSDT场景设计器 快速搭建3D场景。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">点云是空间中的一组数据点。 这些点<span style="color: black;">能够</span><span style="color: black;">暗示</span> 3D 形状或对象。 <span style="color: black;">每一个</span>点位置都有其一组笛卡尔坐标(X、Y、Z)。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">然则</span>,<span style="color: black;">咱们</span><span style="color: black;">持有</span><span style="color: black;">区别</span>的工具,<span style="color: black;">能够</span>比以往更直接地处理激光雷达数据。 这篇博文将教你一种在 Python 中读取、操作和可视化激光雷达数据的简单<span style="color: black;">办法</span>。</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">1、读取和<span style="color: black;">拜访</span>激光雷达数据</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在本教程中,<span style="color: black;">咱们</span><span style="color: black;">运用</span> Laspy(一个用于激光雷达 LAS/LAZ IO 的 Python 库)来摄取点云数据。 稍后,<span style="color: black;">咱们</span>将<span style="color: black;">运用</span>用于 3D 数据处理的现代库 open3D 来可视化 3D 激光雷达数据。 <span style="color: black;">因此</span>让<span style="color: black;">咱们</span>先导入这些库。</span></p>import laspy
import open3d as o3d
import numpy as np<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">让<span style="color: black;">咱们</span>用 Laspy 读取激光雷达数据。 读取是<span style="color: black;">运用</span> laspy.read() 函数完成的。 <span style="color: black;">倘若</span>你只想要元数据而不想要点,<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">运用</span> laspy.open() 。</span></p>las = laspy.read(“data/lidar.las”)
las<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">一旦<span style="color: black;">咱们</span><span style="color: black;">运用</span> laspy.read() 进行读取,就会<span style="color: black;">得到</span>元数据和点云数据。 <span style="color: black;">咱们</span>的激光雷达数据的 las 标头如下所示。</span></p><LasData(1.1, point fmt: <PointFormat(1, 0 bytes of extra dims)>, 277573 points, 1 vlrs)><p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">它<span style="color: black;">包括</span> las 头、点格式、点计数和 vlrs。 <span style="color: black;">咱们</span><span style="color: black;">亦</span><span style="color: black;">能够</span>像<span style="color: black;">这般</span>单独调用它们以<span style="color: black;">得到</span><span style="color: black;">每一个</span>单独的输出。</span></p>las.header
las.header.point_format
las.header.point_count
las.vlrs<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">摄取的文件还<span style="color: black;">包括</span>点数据。 <span style="color: black;">首要</span>,让<span style="color: black;">咱们</span><span style="color: black;">检测</span>一下<span style="color: black;">咱们</span>已阅读的激光雷达文件的可用功能。</span></p>list(las.point_format.dimension_names)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在这种<span style="color: black;">状况</span>下,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">运用</span>以下功能。 请<span style="color: black;">重视</span>,这取决于 LAS 版本。</span></p>[X,
Y,
Z,
intensity,
return_number,
number_of_returns,
scan_direction_flag,
edge_of_flight_line,
classification,
synthetic,
key_point,
withheld,
scan_angle_rank,
user_data,
point_source_id,
gps_time]<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">针对</span>点数据,<span style="color: black;">咱们</span>有 X、Y 、 Z、强度、<span style="color: black;">归类</span>、GPS 时间和其他<span style="color: black;">有些</span>基本维度。 例如,让<span style="color: black;">咱们</span><span style="color: black;">瞧瞧</span>其中的<span style="color: black;">有些</span>维度。</span></p>las.X
las.intensity
las.gps_time<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">输出是<span style="color: black;">表率</span> X、强度和 GPS 时间的数字数组。</span></p># X
array()
#Intensity
array(, dtype=uint16)
# gps_time
array([5880.963028, 5880.963032, 5880.978038, ..., 5886.739728,
5886.739733, 5886.739738])<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">归类</span>是另一个基本维度,你<span style="color: black;">能够</span><span style="color: black;">运用</span> las.classification 调用,它将<span style="color: black;">供给</span>一个数字数组。 <span style="color: black;">然则</span>,<span style="color: black;">倘若</span>想从激光雷达数据中获取<span style="color: black;">独一</span>的<span style="color: black;">归类</span>代码编号,则<span style="color: black;">能够</span>调用以下代码。</span></p>set(list(las.classification))<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在<span style="color: black;">咱们</span>的例子中,<span style="color: black;">仅有</span>四个类。</span></p>1 = Unassigned
2 = Ground
5 = High Vegetation
6 = Building<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">LiDAR数据的<span style="color: black;">归类</span><span style="color: black;">方法</span><span style="color: black;">不仅</span>是<span style="color: black;">咱们</span><span style="color: black;">持有</span>的类别。 <span style="color: black;">相关</span>类和相应 LAS 格式的完整<span style="color: black;">仔细</span>信息,请参阅 ArcGIS 文档页面。</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">2、创建、过滤和写入点云数据</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">要创建 3D 点云数据,<span style="color: black;">咱们</span><span style="color: black;">能够</span>像<span style="color: black;">这般</span><span style="color: black;">运用</span> Numpy 将 X、Y 和 Z 维度堆叠在<span style="color: black;">一块</span>。</span></p>point_data = np.stack(, axis=0).transpose((1, 0))
point_data<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">输出是一个 3 维数组,如下所示。</span></p>array([[ 68506260, 390272760, 31571],
[ 68506057, 390272764, 31572],
[ 68505659, 390272774, 31599],
...,
[ 68747636, 389918893, 31996],
[ 68747762, 389918889, 32296],
[ 68747965, 389918898, 32223]])<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span><span style="color: black;">晓得</span>数据的<span style="color: black;">归类</span>代码,<span style="color: black;">因此呢</span><span style="color: black;">能够</span>过滤掉<span style="color: black;">咱们</span>想要的任何类别。 例如,<span style="color: black;">咱们</span>可以运行以下代码来仅过滤掉建筑类。</span></p>buildings = laspy.create(point_format=las.header.point_format, file_version=las.header.version)
buildings.points = las.points<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">亦</span><span style="color: black;">能够</span>像<span style="color: black;">这般</span>用.write()函数将<span style="color: black;">咱们</span>筛选出来的建筑类点快速写入.las文件。</span></p>buildings.write(‘buildings.las’)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">此刻</span><span style="color: black;">咱们</span>有一个新的激光雷达图像,其中只<span style="color: black;">保留</span>了建筑物数据。 让<span style="color: black;">咱们</span>继续点云数据可视化。</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">3、3D 点云可视化</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Laspy <span style="color: black;">无</span>可视化<span style="color: black;">办法</span>,<span style="color: black;">因此呢</span><span style="color: black;">咱们</span>将<span style="color: black;">运用</span> open3d 库。 <span style="color: black;">咱们</span><span style="color: black;">首要</span>创建 open3D 几何图形并传递<span style="color: black;">咱们</span>之前创建的点数据。 最后,<span style="color: black;">咱们</span><span style="color: black;">运用</span> open3d 可视化来绘制几何图形。</span></p>geom = o3d.geometry.PointCloud()
geom.points = o3d.utility.Vector3dVector(point_data)
o3d.visualization.draw_geometries()<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">这般</span>做的好处是它<span style="color: black;">亦</span>适用于 Jupyter Notebook。 它<span style="color: black;">能够</span>在单独的输出窗口中呈现 3D 可视化。 这是<span style="color: black;">运用</span> Open3D 的数据的 3D 可视化。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/e283deeb9ce141c7978cc77a4136492f~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728805476&x-signature=NlQ2a%2FjBgkyXnJJoG11Ck%2F%2BWnB8%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">原文链接:http://www.bimant.com/blog/process-lidar-point-cloud-with-python/</span></p>
你的话语如春风拂面,让我心生暖意。
页:
[1]