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 covers the standard ICP.
Iterative Closest Point¶
Iterative closest point (ICP) is an algorithm utilized to minimize the difference between two point clouds.
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.
Apply the obtained transformation to source point cloud.
Iterate (re-associate the points, and so on).
For details regarding the PCL Registration module and its internal algorithmic details, please refer to the registration_api for details.
Note
This tutorial is applicable for execution both within inside and outside a Docker* image. It assumes that the pcl-oneapi-tutorials Deb package is 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.