Intel® oneAPI Base Toolkit's Iterative Closest Point (ICP)¶
The standard Iterative Closest Point (ICP) has been optimized using Intel® oneAPI Base Toolkit. Joint ICP and Generalized ICP are not currently optimized with Intel® oneAPI Base Toolkit. This tutorial will cover the standard ICP.
Iterative Closest Point¶
Iterative closest point (ICP) is an algorithm employed to minimize the difference between two clouds of points.
The ICP steps are:
For each point in the source point cloud, match the closest point in the reference/target point cloud.
Estimate the combination of rotation and translation using a root mean square point to point distance metric minimization technique which will best align each source point to its match found in the previous step.
Transform the source points using the obtained transformation.
Iterate (re-associate the points, and so on).
For details regarding the PCL Registration module and it’s internal algorithmic details, please refer to the registration_api for details.
Note
This tutorial can be run both inside and outside a Docker* image. We assume that the pcl-oneapi-tutorial Deb package has been installed, and the user has copied the tutorial directory from /opt/intel/pcl/oneapi/tutorials/ to a user-writable directory.
Prepare the environment:
oneapi_icp_example.cpp
should be in the directory with following content:1#include <pcl/oneapi/registration/icp.h> 2#include <pcl/console/parse.h> 3#include <pcl/point_types.h> 4#include <pcl/point_cloud.h> 5#include <pcl/point_representation.h> 6#include <pcl/io/pcd_io.h> 7 8 9using namespace pcl; 10using namespace pcl::io; 11using namespace pcl::console; 12 13/* ---[ */ 14int 15main (int argc, char** argv) 16{ 17 std::cout << "Running on device: " << dpct::get_default_queue().get_device().get_info<sycl::info::device::name>() << "\n"; 18 19 // Load the files 20 PointCloud<PointXYZ>::Ptr src, tgt; 21 src.reset (new PointCloud<PointXYZ>); 22 tgt.reset (new PointCloud<PointXYZ>); 23 if (loadPCDFile ("test_P.pcd", *src) == -1 || loadPCDFile ("test_Q.pcd", *tgt) == -1) 24 { 25 print_error ("Error reading the input files!\n"); 26 return (-1); 27 } 28 29 PointCloud<PointXYZ> output; 30 // Compute the best transformtion 31 pcl::oneapi::IterativeClosestPoint<PointXYZ, PointXYZ> reg; 32 reg.setMaximumIterations(20); 33 reg.setTransformationEpsilon(1e-12); 34 reg.setMaxCorrespondenceDistance(2); 35 36 reg.setInputSource(src); 37 reg.setInputTarget(tgt); 38 39 // Register 40 reg.align(output); //point cloud output of alignment i.e source cloud after transformation is applied. 41 42 Eigen::Matrix4f transform = reg.getFinalTransformation(); 43 44 std::cerr << "Transform Matrix:" << std::endl; 45 std::cerr << transform << std::endl; 46 // Write transformed data to disk 47 savePCDFileBinary ("source_transformed.pcd", output); 48} 49/* ]--- */
Source the Intel® oneAPI Base Toolkit environment:
(Optional) Setup proxy setting to download test data:
Build the code:
Run the binary:
Expected results example:
Code Explanation¶
Define two input point Clouds (src, tgt), declare the output point cloud, and load the test data from GitHub*.
Declare oneapi ICP, and set the input configuration parameters.
Set the two input point clouds for the ICP module, and call the method to align the two point clouds. The align method populates the output point cloud, passed as a parameter, with the src point cloud transformed using the computed transformation matrix.
Get the computed matrix transformation, print it, and save the transformed point cloud.