Vla*_*lan 5 c++ cloud mapping image point
对于我的工作,我必须将点云转换为灰度(深度)图像,这意味着云中每个XYZ点的z坐标表示灰色阴影。为了将Z坐标从[z_min,z_max]区间映射到[0..255]区间,我使用了Arduino的map函数:
float map(float x, float in_min, float in_max, float out_min, float out_max)
{ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }
完成此操作后,我需要将结果写入图像,问题是我拥有的云可以具有数百万个点,因此我不能只将它们一一写入到图像中。假设我有3000x1000个有序XY点。如果我想将它们写入700x300像素的图像该怎么办?我希望这个问题很清楚,在此先感谢您的回答。
我已经设法找到解决我的问题的方法。这是一个很长的堆栈溢出算法,但请耐心等待。这个想法是将 XY 灰度点向量写入pgm文件。
步骤 1: - 将 XYZ 点云cloud_to_greyscale转换为XY 灰度点向量并接收 a作为参数的函数:cloud
for each point pt in cloud
point_xy_greyscale.x <- pt.x
point_xy_greyscale.y <- pt.y
point_xy_greyscale.greyscale <- map(pt.z, z_min, z_max, 0, 255)
greyscale_vector.add(point_xy_greyscale)
loop
return greyscale_vector
Run Code Online (Sandbox Code Playgroud)
步骤 2: greyscale_to_image - 将先前返回的向量写入 a 的函数greyscale_image,该类具有 a width、 aheight和通常_pixels对应于二维数组的成员unsigned short。该函数接收以下参数: a greyscale_vector(将转换为图像)和 an x_epsilon,它将帮助我们界定x点的像素坐标,因为知道x点坐标是浮点数(因此不适合作为数组索引)。
一些背景信息:我正在研究一种称为widop云的东西,所以在我的 3D 空间中x是width、y是depth和z是height。另外值得注意的是,y对于integer我的问题来说,height图像的 很容易找到:它是y_max - y_min。要找到width图像的大小,请遵循下面的算法,如果不清楚,我会回答任何问题,并且愿意接受建议。
img_width <- 0; // image width
img_height <- y_max - y_min + 1 // image height
// determining image width
for each point greyscale_xy_point in greyscale_vector
point_x_cell <- (pt.x - x_min) * x_epsilon * 10
if point_x_cell > img_width
img_width <- point_x_cell + 1
loop
// defining and initializing image with the calculated height and width
greyscale_img(img_width, img_height)
// initializing greyscale image points
for y <- 0 to greyscale_img.height
for x <- 0 to greyscale_img.width
greyscale_img[y][x] = 0
loop
loop
// filling image with vector data
for each point point_xy_greyscale in greyscale_vector
image_x = (point_xy_greyscale.x - x_min) * x_epsilon * 10
image_y = point_xy_greyscale.y - y_min
greyscale_image[image_y][image_x] = point_xy_greyscale.greyscale
loop
return greyscale_image
Run Code Online (Sandbox Code Playgroud)
剩下要做的唯一一件事就是将图像写入文件,但这很容易做到,您可以在前面与 pgm 格式相关的链接中找到格式规则。我希望这可以帮助别人。
EDIT_1:我添加了结果的图片。它应该是一条铁路,之所以相当暗,是因为有些物体很高,所以地面物体较暗。
| 归档时间: |
|
| 查看次数: |
3913 次 |
| 最近记录: |