点云处理 您所在的位置:网站首页 鸟瞰图和俯视图的区别是什么 点云处理

点云处理

2024-06-05 15:25| 来源: 网络整理| 查看: 265

写在前面

最近在求职,发现激光雷达就业机会更多,而且我在这方面基础相对薄弱些,所以打算补一补。

只要开始,就不晚。

这是一篇英文博客翻译,内容是将点云数据转换成鸟瞰图,虽然CSDN上已经有翻译,但我还是想自己过一遍,以加深理解。

接下来我要好好学学PCL!

点云数据

点云数据可以表示为具有N行和至少3列的numpy数组。每行对应一个点,其在空间中的位置至少使用3个值表示,即(x,y,z)。 在这里插入图片描述 如果点云数据来自LIDAR传感器,那么它可能具有每个点的附加值,例如“反射率”,其是在该位置中障碍物反射多少激光光束的量度。在这种情况下,点云数据可能是Nx4的数组。

图像与点云坐标

点云的坐标系与图像中的坐标系具有完全不同的含义。 下图中,蓝色为图像坐标系,橙色为点云坐标系。 在这里插入图片描述 关于图像需要注意的一些重要事项:

图像中的坐标值始终为正原点位于左上角坐标是整数值

有关点云坐标的注意事项:

点云中的坐标值可以是正数或负数坐标可以采用实数编号的值正x轴表示向前正y轴表示左正z轴表示向上 创建点云数据的鸟瞰视图 鸟瞰图的相关坐标系

为了创建鸟眼视图,要使用点云数据x和y轴上的值。 在这里插入图片描述 但是,正如上图所示,必须小心并考虑以下事项:

x和y轴意味着相反的事情x和y轴指向相反的方向必须移动值,以便(0,0)是图像中可能的最小值 设置感兴趣区域

仅关注点云的特定区域通常很有用。因此,我们希望创建一个过滤器,仅保留我们感兴趣区域内的点。

由于我们正在俯视数据,并且要将其转换为图像,因此要使用与图像坐标轴更加一致的方向。下面,指定集中在相对于原点的值的范围。原点左侧的任何内容都将被视为负数,而右侧的任何内容都将被视为正数。点云的x轴将被解释为向前的方向(鸟瞰图向上的方向)。

下面的代码将感兴趣的矩形设置为在原点的两侧,跨度为10米,并在其前面20米处。

side_range=(-10, 10) # left-most to right-most fwd_range=(0, 20) # back-most to forward-most

接下来,创建一个过滤器,仅保留实际位于指定的矩形内的点。

# EXTRACT THE POINTS FOR EACH AXIS x_points = points[:, 0] y_points = points[:, 1] z_points = points[:, 2] # FILTER - To return only indices of points within desired cube # Three filters for: Front-to-back, side-to-side, and height ranges # Note left side is positive y axis in LIDAR coordinates f_filt = np.logical_and((x_points > fwd_range[0]), (x_points -side_range[1]), (y_points >> x_img.min() 7 >>> x_img.max() 199 >>> y_img.min() 1 >>> y_img.max() 199 像素值

到这里,已经使用点数据来指定图像中的x和y位置,现在需要做的是指定这些像素位置填充的值。一种方法是填充高度数据。 有两件事要注意:

像素值应为整数像素值应该是0-255范围内的值

可以从数据中获取最小和最大高度值,并重新缩放至0-255范围。另一种方法是,设置我们想要关注的高度值范围,并且高于或低于该范围的任何值都被设置为最小值和最大值。这种方法很有用,因为它允许我们从感兴趣的区域获得最大限度的细节。

在下面的代码中,将范围设置为原点下方2米,原点上方半米。

height_range = (-2, 0.5) # bottom-most to upper-most # CLIP HEIGHT VALUES - to between min and max heights pixel_values = np.clip(a = z_points, a_min=height_range[0], a_max=height_range[1])

接下来,将这些值重新缩放到0到25​​5之间,并将数据类型转换为整数。

def scale_to_255(a, min, max, dtype=np.uint8): """ Scales an array of values from specified min, max range to 0-255 Optionally specify the data type of the output (default is uint8) """ return (((a - min) / float(max - min)) * 255).astype(dtype) # RESCALE THE HEIGHT VALUES - to be between the range 0-255 pixel_values = scale_to_255(pixel_values, min=height_range[0], max=height_range[1]) 创建图像数组

现在准备创建图像,首先初始化一个数组,其尺寸取决于我们在矩形中数值的范围和选择的分辨率;然后使用转换为像素位置的x和y点值来指定数组中的索引,并为这些索引分配像素值。

# INITIALIZE EMPTY ARRAY - of the dimensions we want x_max = 1+int((side_range[1] - side_range[0])/res) y_max = 1+int((fwd_range[1] - fwd_range[0])/res) im = np.zeros([y_max, x_max], dtype=np.uint8) # FILL PIXEL VALUES IN IMAGE ARRAY im[y_img, x_img] = pixel_values 可视化

目前,图像存储为numpy数组。如果希望将其可视化,可以将其转换为PIL图像。

# CONVERT FROM NUMPY ARRAY TO A PIL IMAGE from PIL import Image im2 = Image.fromarray(im) im2.show()

在这里插入图片描述 人类并不善于分辨灰色和阴影之间的区别,因此可以使用光谱颜色映射来更容易地分辨出差异。可以在matplotlib中做到这一点。

import matplotlib.pyplot as plt plt.imshow(im, cmap="spectral", vmin=0, vmax=255) plt.show()

在这里插入图片描述 实际上,这种方式生成的图像与PIL绘制的图像具有完全相同的信息量,因此机器学习算法能够区分高度差异,即使我们人类不能非常清楚地看到差异。

完整代码

为方便起见,将上面的所有代码放在一个函数中,它将鸟瞰图作为一个numpy数组返回。然后,可以使用喜欢的任何方法对其进行可视化,或者将numpy数组输入到机器学习算法中。

import numpy as np # ============================================================================== # SCALE_TO_255 # ============================================================================== def scale_to_255(a, min, max, dtype=np.uint8): """ Scales an array of values from specified min, max range to 0-255 Optionally specify the data type of the output (default is uint8) """ return (((a - min) / float(max - min)) * 255).astype(dtype) # ============================================================================== # POINT_CLOUD_2_BIRDSEYE # ============================================================================== def point_cloud_2_birdseye(points, res=0.1, side_range=(-10., 10.), # left-most to right-most fwd_range = (-10., 10.), # back-most to forward-most height_range=(-2., 2.), # bottom-most to upper-most ): """ Creates an 2D birds eye view representation of the point cloud data. Args: points: (numpy array) N rows of points data Each point should be specified by at least 3 elements x,y,z res: (float) Desired resolution in metres to use. Each output pixel will represent an square region res x res in size. side_range: (tuple of two floats) (-left, right) in metres left and right limits of rectangle to look at. fwd_range: (tuple of two floats) (-behind, front) in metres back and front limits of rectangle to look at. height_range: (tuple of two floats) (min, max) heights (in metres) relative to the origin. All height values will be clipped to this min and max value, such that anything below min will be truncated to min, and the same for values above max. Returns: 2D numpy array representing an image of the birds eye view. """ # EXTRACT THE POINTS FOR EACH AXIS x_points = points[:, 0] y_points = points[:, 1] z_points = points[:, 2] # FILTER - To return only indices of points within desired cube # Three filters for: Front-to-back, side-to-side, and height ranges # Note left side is positive y axis in LIDAR coordinates f_filt = np.logical_and((x_points > fwd_range[0]), (x_points -side_range[1]), (y_points


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有