深度图像的获取方法有激光雷达深度成像法,计算机立体视觉成像,坐标测量机法,莫尔条纹法,结构光法等等。
针对深度图像的研究重点主要集中在以下几个方面:
深度图像(Depth Images)也被称为距离影像(Range Image),是指将从图像采集器到场景中各点的距离值作为像素值的图像,它直接反应了景物可见表面的几何形状,利用它可以很方便的解决3D目标描述中的许多问题,深度图像经过点云变换可以计算为点云数据,有规则及有必要信息的点云数据可以反算为深度图像数据。
与点云的区别:
点云:当一束激光照射到物体表面时,所反射的激光会携带方位、距离等信息。若将激光束按照某种轨迹进行扫描,便会边扫描边记录到反射的激光点信息,由 于扫描极为精细,则能够得到大量的激光点,因而就可形成激光点云。点云格式有*.las ;*.pcd; *.txt等。
在PCL 中深度图像与点云最主要的区别在于其近邻的检索方式的不同,并且可以互相转换。
深度图像经过坐标转换可以计算为点云数据;有规则及必要信息的点云数据可以反算为深度图像
1.从点云中获取深度图:
createFromPointCloud(
pointCloud, angularResolution, maxAngleWidth, maxAngleHeight,
sensorPose, coordinate_frame, noiseLevel, minRange, borderSize)
#pragma once
#include
#include
#include
#include
#include
//全局参数
float angular_resolution = 0.5f;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
void setViewerPose(pcl::visualization::PCLVisualizer & viewer,const Eigen::Affine3f& viewer_pose)
{
Eigen::Vector3f pose_vector = viewer_pose * Eigen::Vector3f(0, 0, 0);
Eigen::Vector3f look_at_vector = viewer_pose.rotation() * Eigen::Vector3f(0, 0, 1) + pose_vector;
Eigen::Vector3f up_vector = viewer_pose.rotation() * Eigen::Vector3f(0, -1, 0);
viewer.setCameraPosition(pose_vector[0], pose_vector[1], pose_vector[2],
look_at_vector[0],look_at_vector[1], look_at_vector[2],
up_vector[0], up_vector[1], up_vector[2]);
//viewer.updateCamera();
}
void main_range_image_show()
{
angular_resolution = pcl::deg2rad(angular_resolution);
//读取点云
pcl::PointCloud ::Ptr cloud(new pcl::PointCloud);
pcl::PointCloud& point_cloud = *cloud;
pcl::io::loadPCDFile("maize.pcd", *cloud);
Eigen::Affine3f scene_sensor_pose(Eigen::Affine3f::Identity());
scene_sensor_pose = Eigen::Affine3f(Eigen::Translation3f(point_cloud.sensor_origin_[0],
point_cloud.sensor_origin_[1],
point_cloud.sensor_origin_[2])) *Eigen::Affine3f(point_cloud.sensor_orientation_);
//从点云创建深度图像对象
float noise_level = 0.0;
float min_range = 0.0f;
int border_size = 1;
boost::shared_ptr range_image_ptr(new pcl::RangeImage);
pcl::RangeImage& range_image = *range_image_ptr;
range_image.createFromPointCloud(*cloud, angular_resolution, pcl::deg2rad(360.0f), pcl::deg2rad(180.0f),
scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
//创建3D视图并添加点云进行显示
pcl::visualization::PCLVisualizer viewer("3d viewer");
viewer.setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerCustomrange_image_color_handler
(range_image_ptr, 1, 1, 1);
viewer.addPointCloud(range_image_ptr, range_image_color_handler, "range_image");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range_image");
//添加坐标系,并对原始点云进行可视化
//viewer.addCoordinateSystem (1.0f);
//PointCloudColorHandlerCustom point_cloud_color_handler (point_cloud_ptr, 150, 150, 150);
//viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");
viewer.initCameraParameters();
setViewerPose(viewer, range_image.getTransformationToWorldSystem());
//显示深度图像
pcl::visualization::RangeImageVisualizer range_image_widget("Range_image");
range_image_widget.showRangeImage(range_image);
//主循环
while (!viewer.wasStopped())
{
range_image_widget.spinOnce();
viewer.spinOnce();
pcl_sleep(0.01);
if (1)
{
scene_sensor_pose = viewer.getViewerPose();
range_image.createFromPointCloud(*cloud, angular_resolution, pcl::deg2rad(360.0f), pcl::deg2rad(180.0f), scene_sensor_pose, pcl::RangeImage::LASER_FRAME, noise_level, min_range, border_size);
range_image_widget.showRangeImage(range_image);
}
}
}
2.从深度图中提取边界
我们对三种不同类型的点感兴趣:
以下是一个典型的激光雷达获得的3D数据对应的点云图:
#pragma once
#include
#include
#include
#include
#include
#include
float rangular = 0.5f;
pcl::RangeImage::CoordinateFrame coordinateFrame = pcl::RangeImage::CAMERA_FRAME;
void range_image_border_extraction()
{
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
pcl::io::loadPCDFile("rabbit.pcd", *cloud);
Eigen::Affine3f scene_sensor_pose(Eigen::Affine3f::Identity());
//从点云创建深度图
float noise_level = 0.0f;
float min_range = 0.0f;
float border_size = 1;
boost::shared_ptrrange_image_ptr(new pcl::RangeImage);
pcl::RangeImage& range_image = *range_image_ptr;
range_image.createFromPointCloud(*cloud, pcl::deg2rad(rangular), pcl::deg2rad(360.f), pcl::rad2deg(180.0f),
scene_sensor_pose, coordinateFrame, noise_level, min_range, border_size);
//可视化
pcl::visualization::PCLVisualizer viewer("3d viewer");
viewer.setBackgroundColor(1, 1, 1);
viewer.addCoordinateSystem(1.0f);
pcl::visualization::PointCloudColorHandlerCustom
point_cloud_color_handler(cloud, 0, 0, 0);
viewer.addPointCloud(cloud, point_cloud_color_handler, "original point cloud");
//提取边界
pcl::RangeImageBorderExtractor border_extractor(&range_image);
pcl::PointCloudborder_descriptions;
border_extractor.compute(border_descriptions);
//在三维浏览器中显示
pcl::PointCloud::Ptr border_points_ptr(new pcl::PointCloud), veil_points_ptr(new pcl::PointCloud), shadow_points_ptr(new pcl::PointCloud);
pcl::PointCloud& border_points = *border_points_ptr, & veil_points = *veil_points_ptr, & shadow_points = *shadow_points_ptr;
for (int y = 0; y < (int)range_image.height; ++y)
{
for (int x = 0; x < (int)range_image.width; ++x)
{
if (border_descriptions.points[y * range_image.width + x].traits[pcl::BORDER_TRAIT__OBSTACLE_BORDER])
border_points.points.push_back(range_image.points[y * range_image.width + x]);
if (border_descriptions.points[y * range_image.width + x].traits[pcl::BORDER_TRAIT__VEIL_POINT])
veil_points.points.push_back(range_image.points[y * range_image.width + x]);
if (border_descriptions.points[y * range_image.width + x].traits[pcl::BORDER_TRAIT__SHADOW_BORDER])
shadow_points.points.push_back(range_image.points[y * range_image.width + x]);
}
}
pcl::visualization::PointCloudColorHandlerCustom border_points_color_handler(border_points_ptr, 0, 255, 0);
viewer.addPointCloud(border_points_ptr, border_points_color_handler, "border points");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "border points");
pcl::visualization::PointCloudColorHandlerCustom veil_points_color_handler(veil_points_ptr, 255, 0, 0);
viewer.addPointCloud(veil_points_ptr, veil_points_color_handler, "veil points");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "veil points");
pcl::visualization::PointCloudColorHandlerCustom shadow_points_color_handler(shadow_points_ptr, 0, 255, 255);
viewer.addPointCloud(shadow_points_ptr, shadow_points_color_handler, "shadow points");
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "shadow points");
//-------------------------------------
// -----在深度图像中显示点集-----
// ------------------------------------
pcl::visualization::RangeImageVisualizer* range_image_borders_widget = NULL;
range_image_borders_widget =
pcl::visualization::RangeImageVisualizer::getRangeImageBordersWidget(range_image, -std::numeric_limits::infinity(), std::numeric_limits::infinity(), false, border_descriptions, "Range image with borders");
// -------------------------------------
//--------------------
// -----主循环-----
//--------------------
while (!viewer.wasStopped())
{
range_image_borders_widget->spinOnce();
viewer.spinOnce(1000);
//pcl_sleep(0.01);
}
system("pause");
}