3d激光雷达开发(icp匹配)

时间:2022-11-23 22:55:58



        所谓匹配,其实就是看两个点云数据里面,哪些关键点是一样的。这样就可以把一个点云移动到另外合适的位置,组成一个新的点云。一般来说,单个机器人上面,3d激光扫描到的空间总是有限的,有了这个匹配算法,就可以把所有的点云组合成一个完整的3d地图了。参考的代码原来链接在这,​​https://pcl.readthedocs.io/projects/tutorials/en/master/iterative_closest_point.html#iterative-closest-point​

        在pcl库里面,这个匹配过程称之为registration,有一点拗口,不清楚为什么取这个名字。

1、准备iterative_closest_point.cpp

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

int
main (int argc, char** argv)
{
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>);

// Fill in the CloudIn data
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 << "Saved " << cloud_in->size () << " data points to input:" << std::endl;

for (auto& point : *cloud_in)
std::cout << point << std::endl;

*cloud_out = *cloud_in;

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

std::cout << "Transformed " << cloud_in->size () << " data points:" << 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 << "has converged:" << icp.hasConverged() << " score: " <<
icp.getFitnessScore() << std::endl;
std::cout << icp.getFinalTransformation() << std::endl;

return (0);
}

2、准备CMakeLists.txt文件

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(iterative_closest_point)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (iterative_closest_point iterative_closest_point.cpp)
target_link_libraries (iterative_closest_point ${PCL_LIBRARIES})

3、生成sln工程,开始编译

3d激光雷达开发(icp匹配)

4、执行iterative_closest_point.exe

3d激光雷达开发(icp匹配)

 

5、补充怎么从旋转矩阵获取yaw/pitch/roll/x/y/z

 

3d激光雷达开发(icp匹配)