请选择 进入手机版 | 继续访问电脑版

点云技术相关产学研社区

 找回密码
 立即注册加入PCL中国点云技术相关产学研社区

扫一扫,访问微社区

查看: 3493|回复: 0

从有序三维点云到二维图像

[复制链接]
发表于 2020-9-25 20:53:01 | 显示全部楼层 |阅读模式
为了利用现有的二维视觉领域的算法,有时需要将从三维点云生成二维合成图像,当然对于任意视角的,肯定用图形渲染技术,设置相机参数等。但对于深度摄像头保存的点云数据,比较特殊,其是有序点云,点云库pcl里面提供了一些相关的接口和案例
https://github.com/PointCloudLibrary/pcl/blob/master/tools/pcd2png.cpp
这里一定要注意,是有序的点云数据,对于删除了,nan值的rgbd点云数据,就不能用这些接口了。
PointCloudImageExtractor
以及其对应的多个子类,具体参考
https://pointclouds.org/documentation/classpcl_1_1io_1_1_point_cloud_image_extractor.html

  1. template <typename PointT> bool
  2. pcl::io::PointCloudImageExtractorFromNormalField<PointT>::extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const
  3. {
  4.    std::vector<pcl::PCLPointField> fields;
  5.    int field_x_idx = pcl::getFieldIndex<PointT> ("normal_x", fields);
  6.    int field_y_idx = pcl::getFieldIndex<PointT> ("normal_y", fields);
  7.    int field_z_idx = pcl::getFieldIndex<PointT> ("normal_z", fields);
  8.    if (field_x_idx == -1 || field_y_idx == -1 || field_z_idx == -1)
  9.      return (false);
  10.    const std::size_t offset_x = fields[field_x_idx].offset;
  11.    const std::size_t offset_y = fields[field_y_idx].offset;
  12.    const std::size_t offset_z = fields[field_z_idx].offset;
  13.   
  14.    img.encoding = "rgb8";
  15.    img.width = cloud.width;
  16.    img.height = cloud.height;
  17.    img.step = img.width * sizeof (unsigned char) * 3;
  18.    img.data.resize (img.step * img.height);
  19.   
  20.    for (std::size_t i = 0; i < cloud.size (); ++i)
  21.    {
  22.      float x;
  23.      float y;
  24.      float z;
  25.      pcl::getFieldValue<PointT, float> (cloud[i], offset_x, x);
  26.      pcl::getFieldValue<PointT, float> (cloud[i], offset_y, y);
  27.      pcl::getFieldValue<PointT, float> (cloud[i], offset_z, z);
  28.      img.data[i * 3 + 0] = static_cast<unsigned char>((x + 1.0) * 127);
  29.      img.data[i * 3 + 1] = static_cast<unsigned char>((y + 1.0) * 127);
  30.      img.data[i * 3 + 2] = static_cast<unsigned char>((z + 1.0) * 127);
  31.    }
  32.   
  33.    return (true);
  34. }
复制代码
以normal对应的类为例,实现比较简单,基本上就是将对应索引的normal直接赋值给图像上对应的像素值
回复

使用道具 举报

本版积分规则

QQ|小黑屋|点云技术相关产学研社区 ( 陕ICP备13001629号 )

GMT+8, 2024-3-29 21:20 , Processed in 1.870263 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表