利用PCL实现点云配准

news2024/9/29 7:23:00

一、介绍

This document demonstrates using the Iterative Closest Point algorithm in your code which can determine if one PointCloud is just a rigid transformation of another by minimizing the distances between the points of two pointclouds and rigidly transforming them.

使用ICP算法实现点云的配准,刚性变换4*4矩阵。

How to use the Normal Distributions Transform (NDT) algorithm to determine a rigid transformation between two large point clouds, both over 100,000 points.

使用NDT算法实现大数据的点云配准,刚性变换4*4矩阵。

二、代码

1、ICP算法

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/icp.h>

int main()
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>(5, 1));
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>);

	for (auto& point : *cloud_in)
	{
		point.x = 1024 * rand() / (RAND_MAX + 1.0f);
		point.y = 1024 * rand() / (RAND_MAX + 1.0f);
		point.z = 1024 * rand() / (RAND_MAX + 1.0f);
	}
	std::cout << "cloud_in num = " << cloud_in->size() << " ################## " << std::endl;
	for (auto& point : *cloud_in)
		std::cout << point << std::endl;

	*cloud_out = *cloud_in;
	for (auto& point : *cloud_out)
		point.x += 0.7f;
	std::cout << "cloud_out num = " << cloud_out->size() << " ################## " << std::endl;
	for (auto& point : *cloud_out)
		std::cout << point << std::endl;

	pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
	icp.setInputSource(cloud_in);
	icp.setInputTarget(cloud_out);

	pcl::PointCloud<pcl::PointXYZ> Final;
	icp.align(Final);
	std::cout << "Final num = " << Final.size() << " ################## " << std::endl;
	for (auto& point : Final)
		std::cout << point << std::endl;

	std::cout << "has converged:" << icp.hasConverged() << " score: " << icp.getFitnessScore() << std::endl;
	std::cout << icp.getFinalTransformation() << std::endl;

	return (0);
}

2、NDT算法

    数据链接:链接:https://pan.baidu.com/s/1jR7k5iI-acVyyehKcYbetA?pwd=mr16
    提取码:mr16

#include <iostream>
#include <thread>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/ndt.h>
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/visualization/pcl_visualizer.h>

using namespace std::chrono_literals;
using namespace std;

int main()
{
	// Loading first scan of room.
	pcl::PointCloud<pcl::PointXYZ>::Ptr target_cloud(new pcl::PointCloud<pcl::PointXYZ>);
	if (pcl::io::loadPCDFile<pcl::PointXYZ>("room_scan1.pcd", *target_cloud) == -1)
	{
		PCL_ERROR("Couldn't read file room_scan1.pcd \n");
		return (-1);
	}
	cout << "Loaded " << target_cloud->size() << " data points from room_scan1.pcd" << endl;

	// Loading second scan of room from new perspective.
	pcl::PointCloud<pcl::PointXYZ>::Ptr input_cloud(new pcl::PointCloud<pcl::PointXYZ>);
	if (pcl::io::loadPCDFile<pcl::PointXYZ>("room_scan2.pcd", *input_cloud) == -1)
	{
		PCL_ERROR("Couldn't read file room_scan2.pcd \n");
		return (-1);
	}
	cout << "Loaded " << input_cloud->size() << " data points from room_scan2.pcd" << endl;

	// Filtering input scan to roughly 10% of original size to increase speed of registration.
	pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::ApproximateVoxelGrid<pcl::PointXYZ> approximate_voxel_filter;
	approximate_voxel_filter.setLeafSize(0.2, 0.2, 0.2);
	approximate_voxel_filter.setInputCloud(input_cloud);
	approximate_voxel_filter.filter(*filtered_cloud);
	cout << "Filtered cloud contains " << filtered_cloud->size() << " data points from room_scan2.pcd" << endl;

	// Initializing Normal Distributions Transform (NDT).
	pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> ndt;

	// Setting scale dependent NDT parameters
	// Setting minimum transformation difference for termination condition.
	ndt.setTransformationEpsilon(0.01);
	// Setting maximum step size for More-Thuente line search.
	ndt.setStepSize(0.1);
	// Setting Resolution of NDT grid structure (VoxelGridCovariance).
	ndt.setResolution(1.0);
	// Setting max number of registration iterations.
	ndt.setMaximumIterations(35);
	// Setting point cloud to be aligned.
	ndt.setInputSource(filtered_cloud);
	// Setting point cloud to be aligned to.
	ndt.setInputTarget(target_cloud);

	// Set initial alignment estimate found using robot odometry.
	Eigen::AngleAxisf init_rotation(0.6931, Eigen::Vector3f::UnitZ());
	Eigen::Translation3f init_translation(1.79387, 0.720047, 0);
	Eigen::Matrix4f init_guess = (init_translation * init_rotation).matrix();
	cout << init_guess << endl;

	// Calculating required rigid transform to align the input cloud to the target cloud.
	pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud(new pcl::PointCloud<pcl::PointXYZ>);
	ndt.align(*output_cloud, init_guess);
	cout << ndt.getFinalTransformation() << endl;
	cout << "NDT has converged:" << ndt.hasConverged() << " score: " << ndt.getFitnessScore() << endl;

	// Transforming unfiltered input cloud using found transform.
	pcl::transformPointCloud(*input_cloud, *output_cloud, ndt.getFinalTransformation());
	cout << "transformResult " << output_cloud->size() << " data points from room_scan2.pcd" << endl;

	// Saving transformed input cloud.
	pcl::io::savePCDFileASCII("room_scan2_transformed.pcd", *output_cloud);

	// Initializing point cloud visualizer
	pcl::visualization::PCLVisualizer::Ptr
	viewer_final(new pcl::visualization::PCLVisualizer("3D Viewer"));
	viewer_final->setBackgroundColor(0, 0, 0);

	// Coloring and visualizing target cloud (red).
	pcl::visualization::PointCloudColorHandlerCustom < pcl::PointXYZ>
	target_color(target_cloud, 255, 0, 0);
	viewer_final->addPointCloud<pcl::PointXYZ>(target_cloud, target_color, "target cloud");
	viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud");

	// Coloring and visualizing transformed input cloud (green).
	pcl::visualization::PointCloudColorHandlerCustom < pcl::PointXYZ>
	output_color(output_cloud, 0, 255, 0);
	viewer_final->addPointCloud<pcl::PointXYZ>(output_cloud, output_color, "output cloud");
	viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "output cloud");

	// Starting visualizer
	viewer_final->addCoordinateSystem(1.0, "global");
	viewer_final->initCameraParameters();

	// Wait until visualizer window is closed.
	while (!viewer_final->wasStopped())
	{
		viewer_final->spinOnce(100);
		this_thread::sleep_for(100ms);
	}

	return (0);
}

三、结论

1、ICP

参考:How to use iterative closest point — Point Cloud Library 0.0 documentation 

2、NDT

参考:How to use Normal Distributions Transform — Point Cloud Library 0.0 documentation

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Ishikawa

Ishikawa 石川、鱼骨头、因果 其实我压根不知道 Ishikawa 这个日文就是石川&#xff0c;^_^&#xff0c;视乎也没啥影响

fastadmin动态获取单选框选中值修改页面

需求场景&#xff1a; 在编辑页面中&#xff0c;要求要根据某一单选框&#xff08;字段名称popup&#xff09;的选中值&#xff0c;来动态显示或者隐藏某个div&#xff08;idupload_img&#xff09;。 edit: function () {var popVal $("input[typeradio][namerow[popup]…

CNN(四):ResNet与DenseNet结合--DPN

&#x1f368; 本文为&#x1f517;365天深度学习训练营中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊|接辅导、项目定制 前面实现了ResNet和DenseNet的算法&#xff0c;了解了它们有各自的特点&#xff1a; ResNet&#xff1a;通过建立前面层与后面层之间的“短路…

U8g2 驱动oled自定义中文字库

原文&#xff1a;Arduino驱动LED128X64 - U8g2 参考&#xff1a; Arduino通过u8g2库驱动OLED适合 u8g2 的中文字体&#xff0c;采用文泉驿点阵宋体作为源本&#xff0c;提供 12x12、13x13、14x14、15x15 和 16x16 点阵字库。 本文所需工具下载 我们在项目中大概率会遇到LED显示…

淘宝商品详情(API接口)各大请求示例参考参数

主图&#xff0c;标题&#xff0c;价格&#xff0c;销量&#xff0c;库存&#xff0c;sku&#xff0c;详情信息&#xff0c;促销价&#xff0c;优惠券信息&#xff0c;券后价等 请求示例&#xff1a; <?php// 请求示例 url 默认请求参数已经URL编码处理 // 本示例代码未加…

一文走进时序数据库性能测试工具 TSBS

一、背景 在物联网、车联网等时序数据场景中&#xff0c;数据的高速写入能力至关重要&#xff0c;会对产品方案的可用性、可靠性和扩展性产生影响。 以物联网为例&#xff0c;当面临千万甚至上亿设备、平均每个设备采集几十个到几百个指标时&#xff0c;每秒生成的数据将达到…

使用JavaScript开发网页地图导航

使用JavaScript开发网页地图导航 导航是生活中的一个常见需求&#xff0c;而在互联网时代&#xff0c;网页地图导航成为了人们获取信息和帮助的重要工具。在网页中开发一个地图导航功能&#xff0c;能够提供用户位置定位、路线规划、交通情况等有用的信息&#xff0c;提供便利…

企业权限管理(五)-订单分页

订单分页查询 PageHelper介绍 PageHelper是国内非常优秀的一款开源的mybatis分页插件&#xff0c;它支持基本主流与常用的数据库&#xff0c;例如mysql、oracle、mariaDB、DB2、SQLite、Hsqldb等。 PageHelper使用 集成 引入分页插件有下面2种方式&#xff0c;推荐使用 Maven …

【Redis】Spring/SpringBoot 操作 Redis Java客户端

目录 操作 Redis Java客户端SpringBoot 操作Redis 步骤 操作 Redis Java客户端 1.Jedis 2.Lettuce(主流) <-Spring Data Redis SpringBoot 操作Redis 步骤 1.添加Redis 驱动依赖 2.设置Redis 连接信息 spring.redis.database0 spring.redis.port6379 spring.redis.host…

售后服务行业呼叫中心系统解决方案

随着社会经济的不断发展和消费者对售后服务需求的不断提高&#xff0c;在售后服务行业中&#xff0c;越来越多的企业使用呼叫中心系统来帮助企业提高售后服务质量和效率&#xff0c;提高客户满意度&#xff0c;增强企业竞争力。 一、呼叫中心系统的定义和功能 呼叫中心系统是指…

[mongo]性能机制,分析工具

性能机制 应用端 应用端-选择节点 对于复制集读操作&#xff0c;选择哪个节点是由readPreference决定的 primary/primaryPreferredsecondary/secondaryPreferrednearest 如果不希望一个远距离节点被选择 将它设置为隐藏节点通过标签&#xff08;Tag&#xff09;控制可选的节点…

分享Java技术下AutojsPro7云控代码

引言 有图有真相&#xff0c;那短视频就更是真相了。下面是三大语言的短视频。 Java源码版云控示例&#xff1a; Java源码版云控示例在线视频 核心技术&#xff1a;各个编程语言的WebSocket技术。 Java&#xff1a;Nettey、Net&#xff1a;Fleck、Python&#xff1a;Tornad…

Android Framework底层原理之WMS的启动流程

一 概述 今天&#xff0c;我们介绍 WindowManagerService&#xff08;后续简称 WMS&#xff09;的启动流程&#xff0c;WMS 是 Android 系统中&#xff0c;负责窗口显示的的服务。在 Android 中它也起着承上启下的作用。 如下图&#xff0c;就是《深入理解 Android》书籍中的…

模拟实现消息队列项目(完结) -- 基于MQ的生产者消费者模型

目录 前言 1. 生产者 2. 消费者 3. 启动消息队列服务器 4. 运行效果 结语 前言 在上一章节,我们完成了消息队列的客户端部分,至此我们整个消息队列项目就构建完成了,那我们做的这个消息队列到底有什么效果,以及如何去使用我们自己的消息队列呢?那么本文,就将我们的MQ进行实战操…

GSEA富集分析结果详解

1. GSEA富集分析原理图 2. GSEA富集分析过程 1. 计算富集分数&#xff08;ES&#xff09; 富集分数&#xff1a;S 反应基因集&#xff08;比如某个通路内的基因集&#xff09;成员 s 在排序基因集 L&#xff08;比如根据 logFC 排序的差异基因集&#xff0c;默认降序&#xf…

“为爱起航,一村一书院”在阳朔落地

2023年8月1-5 日&#xff0c;“关爱祖国下一代&#xff0c;助力乡村振兴” 之为爱起航项目在阳朔举行。 本次活动由千里思乡村振兴促进会联合中国文化交流大使组委会携同大湾区19位师生加入到首批“为爱起航&#xff0c;一村一书院”项目中&#xff0c;同时&#xff0c;本项目得…

分页查询从接口到实现,统一对日期类型进行格式化处理

编写Service实现类编写Mapper的sql&#xff0c;但复杂的sql语句需要写到mapper对应的xml文件中日期类型格式化处理 /*** 扩展springmvc框架的消息转换器* param converters*/Overrideprotected void extendMessageConverters(List<HttpMessageConverter<?>> conve…

初识Container

1. 什么是Container&#xff08;容器&#xff09; 要有Container首先要有Image&#xff0c;也就是说Container是通过image创建的。 Container是在原先的Image之上新加的一层&#xff0c;称作Container layer&#xff0c;这一层是可读可写的&#xff08;Image是只读的&#xff0…

天津农商银行智能加密锁管理工具常见问题

天津农商银行智能加密锁管理工具&#xff0c;在使用过程中&#xff0c;可能出现一些莫名的错误&#xff0c;针对亲身遇到的坑&#xff0c;分享给大家&#xff0c;以备不时之需。 一、转账业务导入文件中文汉字出现乱码&#xff0c;如下图。 原因是文件编码不正确&#xff0c;…

MySQL:表的约束和基本查询

表的约束 表的约束——为了让插入的数据符合预期。 表的约束很多&#xff0c;这里主要介绍如下几个&#xff1a; null/not null,default, comment, zerofill&#xff0c;primary key&#xff0c;auto_increment&#xff0c;unique key 。 空属性 两个值&#xff1a;null&am…