【PCL】(十七)从距离图像中提取点云的边界

(十七)从测距图像中提取边界

Object(Obstacle) border:属于物体和的最外面的可见点;

Shadow border:背景中与物体相邻的点;

Veil points:Object border和Shadow border之间的插值点。

以下代码实现将点云投影为距离图像,然后再从距离图像中提取点云的边界。

range_image_border_extraction.cpp

/* \author Bastian Steder */
#include <iostream>
#include <pcl/range_image/range_image.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/range_image_visualizer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/features/range_image_border_extractor.h>
#include <pcl/console/parse.h>
#include <pcl/common/file_io.h> // for getFilenameWithoutExtensiontypedef pcl::PointXYZ PointType;// --------------------
// -----Parameters-----
// --------------------
float angular_resolution = 0.5f;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
bool setUnseenToMaxRange = false;// --------------
// -----Help-----
// --------------
void printUsage (const char* progName)
{std::cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n"<< "Options:\n"<< "-------------------------------------------\n"<< "-r <float>   angular resolution in degrees (default "<<angular_resolution<<")\n"<< "-c <int>     coordinate frame (default "<< (int)coordinate_frame<<")\n"<< "-m           Treat all unseen points to max range\n"<< "-h           this help\n"<< "\n\n";
}// --------------
// -----Main-----
// --------------
int main (int argc, char** argv)
{// --------------------------------------// -----Parse Command Line Arguments-----// --------------------------------------if (pcl::console::find_argument (argc, argv, "-h") >= 0){printUsage (argv[0]);return 0;}if (pcl::console::find_argument (argc, argv, "-m") >= 0){setUnseenToMaxRange = true;std::cout << "Setting unseen values in range image to maximum range readings.\n";}int tmp_coordinate_frame;if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0){coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame);std::cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n";}if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0)std::cout << "Setting angular resolution to "<<angular_resolution<<"deg.\n";angular_resolution = pcl::deg2rad (angular_resolution);// ------------------------------------------------------------------// -----Read pcd file or create example point cloud if not given-----// ------------------------------------------------------------------pcl::PointCloud<PointType>::Ptr point_cloud_ptr (new pcl::PointCloud<PointType>);pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr;pcl::PointCloud<pcl::PointWithViewpoint> far_ranges;Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd");if (!pcd_filename_indices.empty ()){std::string filename = argv[pcd_filename_indices[0]];if (pcl::io::loadPCDFile (filename, point_cloud) == -1){std::cout << "Was not able to open file \""<<filename<<"\".\n";printUsage (argv[0]);return 0;}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_); //std::string far_ranges_filename = pcl::getFilenameWithoutExtension (filename)+"_far_ranges.pcd";   "_far_ranges.pcd";if (pcl::io::loadPCDFile(far_ranges_filename.c_str(), far_ranges) == -1)std::cout << "Far ranges file \""<<far_ranges_filename<<"\" does not exists.\n";}else{std::cout << "\nNo *.pcd file given => Generating example point cloud.\n\n";for (float x=-0.5f; x<=0.5f; x+=0.01f){for (float y=-0.5f; y<=0.5f; y+=0.01f){PointType point;  point.x = x;  point.y = y;  point.z = 2.0f - y;point_cloud.push_back (point);}}point_cloud.width = point_cloud.size ();  point_cloud.height = 1;}// -----------------------------------------------// -----Create RangeImage from the PointCloud-----// -----------------------------------------------float noise_level = 0.0;float min_range = 0.0f;int border_size = 1;pcl::RangeImage::Ptr range_image_ptr (new pcl::RangeImage);pcl::RangeImage& range_image = *range_image_ptr;   range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);range_image.integrateFarRanges (far_ranges);if (setUnseenToMaxRange)range_image.setUnseenToMaxRange ();// --------------------------------------------// -----Open 3D viewer and add point cloud-----// --------------------------------------------pcl::visualization::PCLVisualizer viewer ("3D Viewer");viewer.setBackgroundColor (1, 1, 1);viewer.addCoordinateSystem (0.5f,  scene_sensor_pose);pcl::visualization::PointCloudColorHandlerCustom<PointType> point_cloud_color_handler (point_cloud_ptr, 0, 0, 0);viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");//PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 150, 150, 150);//viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");//viewer.setPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, 2, "range image");// -------------------------// -----提取边界-----// -------------------------pcl::RangeImageBorderExtractor border_extractor (&range_image);pcl::PointCloud<pcl::BorderDescription> border_descriptions;border_extractor.compute (border_descriptions);// ----------------------------------// -----Show points in 3D viewer-----// ----------------------------------// object border, veil points 和shadow pointspcl::PointCloud<pcl::PointWithRange>::Ptr border_points_ptr(new pcl::PointCloud<pcl::PointWithRange>),veil_points_ptr(new pcl::PointCloud<pcl::PointWithRange>),shadow_points_ptr(new pcl::PointCloud<pcl::PointWithRange>);pcl::PointCloud<pcl::PointWithRange>& 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[y*range_image.width + x].traits[pcl::BORDER_TRAIT__OBSTACLE_BORDER])border_points.push_back (range_image[y*range_image.width + x]);if (border_descriptions[y*range_image.width + x].traits[pcl::BORDER_TRAIT__VEIL_POINT])veil_points.push_back (range_image[y*range_image.width + x]);if (border_descriptions[y*range_image.width + x].traits[pcl::BORDER_TRAIT__SHADOW_BORDER])shadow_points.push_back (range_image[y*range_image.width + x]);}}// 对不同类型的点采用不同颜色可视化pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> border_points_color_handler (border_points_ptr, 0, 255, 0);viewer.addPointCloud<pcl::PointWithRange> (border_points_ptr, border_points_color_handler, "border points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "border points");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> veil_points_color_handler (veil_points_ptr, 255, 0, 0);viewer.addPointCloud<pcl::PointWithRange> (veil_points_ptr, veil_points_color_handler, "veil points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "veil points");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> shadow_points_color_handler (shadow_points_ptr, 0, 255, 255);viewer.addPointCloud<pcl::PointWithRange> (shadow_points_ptr, shadow_points_color_handler, "shadow points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "shadow points");//-------------------------------------// -----Show points on range image-----// ------------------------------------pcl::visualization::RangeImageVisualizer* range_image_borders_widget = NULL;range_image_borders_widget =pcl::visualization::RangeImageVisualizer::getRangeImageBordersWidget (range_image, -std::numeric_limits<float>::infinity (), std::numeric_limits<float>::infinity (), false,border_descriptions, "Range image with borders");// -------------------------------------//--------------------// -----Main loop-----//--------------------while (!viewer.wasStopped ()){range_image_borders_widget->spinOnce ();viewer.spinOnce ();pcl_sleep(0.01);}
}

CmakeLists.txt

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(range_image_border_extraction)find_package(PCL 1.3 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (range_image_border_extraction range_image_border_extraction.cpp)
target_link_libraries (range_image_border_extraction ${PCL_LIBRARIES})

编译并运行:

./range_image_border_extraction -m

指定点云:

./range_image_border_extraction table_scene_lms400.pcd  -m -r 0.4 -c 1

在这里插入图片描述

绿点为object border; 红色为veil points; 蓝色为shadow border

数据样本

官方文档

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/511589.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

解决win10系统cmd命令无法使用ssh问题

目录 问题说明&#xff1a;在使用ssh命令连接虚拟机地址时&#xff0c;出现了以下报错&#xff1a;​编辑 解决方法如下&#xff1a; 1.打开Windows设置&#xff0c;搜索点击添加可选功能&#xff1a; 2.点击添加功能&#xff1a; 3.安装Open SSH客户端和Open SSH服务器: …

Camunda 主要表及字段注释

表命名规则 ACT_GE_ &#xff08;GE&#xff09; 表示 general 全局通用数据及设置&#xff0c;各种情况都使用的数据。共 3 张表ACT_HI_ &#xff08;HI&#xff09; 表示 history 历史数据表&#xff0c;包含着程执行的历史相关数据&#xff0c;如结束的流程实例&#xff0c…

ABAP - SALV教程12 显示图标和提示信息

ALV要求字段的值为图标的需求并不多见&#xff0c;一般都用于红黄绿灯&#xff0c;来表示单据的执行状态&#xff0c;添加图标的方式也可以实现红黄绿灯的功能&#xff0c;也可以参考SALV实现红黄绿灯这篇文章&#xff1a;http://t.csdnimg.cn/Dzx7x效果图SAVL列设置为图标图标…

计算机网络-网络安全(二)

1.应用层安全协议&#xff1a; S-HTTP或SHTTP&#xff08;Sec HTTP&#xff09;&#xff0c;安全超文本传输协议&#xff0c;是HTTP扩展&#xff0c;使用TCP的80端口。HTTPS&#xff1a;HTTPSSL&#xff0c;使用TCP的443端口。和TLS&#xff08;传输层安全标准&#xff09;是双…

【论文笔记】Language Models are Unsupervised Multitask Learners

Language Models are Unsupervised Multitask Learners 回顾一下第一代 GPT-1 &#xff1a; 设计思路是 “海量无标记文本进行无监督预训练少量有标签文本有监督微调” 范式&#xff1b;模型架构是基于 Transformer 的叠加解码器&#xff08;掩码自注意力机制、残差、Layernorm…

森林消防常见难题|便携式森林灭火泵轻松化解|深圳恒峰

在自然生态系统中&#xff0c;森林火灾是一大严重威胁。它不仅破坏了生态平衡&#xff0c;还对人类生活和财产构成极大威胁。尤其是在偏远的森林地区&#xff0c;传统的消防设备往往难以及时到达现场&#xff0c;使得火势得以蔓延。然而&#xff0c;随着恒峰智慧科技的研发&…

01. Nginx入门-Nginx简介

Web基础知识 Web协议通信原理 Web协议通信过程 浏览器本身是一个客户端&#xff0c;当输入URL后&#xff0c;首先浏览器会请求DNS服务器&#xff0c;通过DNS获取相应的域名对应的IP。通过IP地址找到对应的服务器后&#xff0c;监理TCP连接。等浏览器发送完HTTP Request&…

FPGA-AXI4接口协议概述

假设我们要传一帧1080P的图片到显示屏显示&#xff0c;那么需要多大的储存空间呢&#xff1f; 一帧1080P的RGB565图像数据需要1920*1080*1633.1776Mb 存储空间 下图是ZYNQ-7000系列中Block RAM的大小&#xff1a; 可以看到最大存储空间的BRAM都不能存储一帧图片&#xff0c;那…

基于springboot+vue的医院挂号就诊系统

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战&#xff0c;欢迎高校老师\讲师\同行交流合作 ​主要内容&#xff1a;毕业设计(Javaweb项目|小程序|Pyt…

管家婆订货易在线商城 VshopProcess 任意文件上传漏洞

免责声明&#xff1a;文章来源互联网收集整理&#xff0c;请勿利用文章内的相关技术从事非法测试&#xff0c;由于传播、利用此文所提供的信息或者工具而造成的任何直接或者间接的后果及损失&#xff0c;均由使用者本人负责&#xff0c;所产生的一切不良后果与文章作者无关。该…

高级货,极大提高效率,个人非常喜欢

软件简介&#xff1a; 软件【下载地址】获取方式见文末。注&#xff1a;推荐使用&#xff0c;更贴合此安装方法&#xff01; FileConverter中文版是一款免费软件&#xff0c;具有强大的功能。它支持多种文件格式的转换&#xff0c;包括视频、音频、文档等。您可以批量转换文件…

代码随想录算法训练营第五一天 | 买股票3

目录 最佳买卖股票时机含冷冻期买卖股票的最佳时机含手续费 LeetCode 309.最佳买卖股票时机含冷冻期 LeetCode 714.买卖股票的最佳时机含手续费 最佳买卖股票时机含冷冻期 给定一个整数数组prices&#xff0c;其中第 prices[i] 表示第 i 天的股票价格 。​ 设计一个算法计算…