Using SampleConsensusInitialAligment (SCIA) to Initial Align Two Point Clouds¶
In this tutorial we will learn how to initial align two point clouds, using SCIA, given the transformation 4x4 matrix.
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_scia.cpp
should be in the directory with following content:1#include <pcl/oneapi/registration/ia_ransac.h> 2#include <pcl/io/pcd_io.h> 3#include <pcl/point_types.h> 4#include <pcl/point_cloud.h> 5 6 7using namespace pcl; 8using namespace pcl::io; 9 10int main (int argc, char** argv) 11{ 12 std::cout << "Running on device: " << dpct::get_default_queue().get_device().get_info<sycl::info::device::name>() << "\n"; 13 14 // Read Point Cloud 15 PointCloud<PointXYZ> cloud_source, cloud_target; 16 PointCloud<FPFHSignature33> FPFH_cloud_source, FPFH_cloud_target; 17 18 if (loadPCDFile<PointXYZ>("../../data/scia_source.pcd", cloud_source) < 0) 19 { 20 std::cerr << "Failed to read alignment source point cloud, please check scia_source.pcd" << std::endl; 21 return (-1); 22 } 23 if (loadPCDFile<PointXYZ>("../../data/scia_target.pcd", cloud_target) < 0) 24 { 25 std::cerr << "Failed to read alignment target point cloud, please check scia_target.pcd" << std::endl; 26 return (-1); 27 } 28 if (loadPCDFile<FPFHSignature33>("../../data/scia_source_fpfh33.pcd", FPFH_cloud_source) < 0) 29 { 30 std::cerr << "Failed to read FPFH feature cloud of alignment source point cloud, please check scia_source_fpfh33.pcd" << std::endl; 31 return (-1); 32 } 33 if (loadPCDFile<FPFHSignature33>("../../data/scia_target_fpfh33.pcd", FPFH_cloud_target) < 0) 34 { 35 std::cerr << "Failed to read FPFH feature cloud of alignment target point cloud, please check scia_target_fpfh33.pcd" << std::endl; 36 return (-1); 37 } 38 39 // GPU calculate 40 pcl::oneapi::SampleConsensusInitialAlignment<PointXYZ, PointXYZ, FPFHSignature33> scia; 41 scia.setInputSource(cloud_source.makeShared()); 42 scia.setInputTarget(cloud_target.makeShared()); 43 scia.setSourceFeatures(FPFH_cloud_source.makeShared()); 44 scia.setTargetFeatures(FPFH_cloud_target.makeShared()); 45 46 constexpr float SACdismin = 0.02f; 47 constexpr int SCANum = 20; 48 constexpr int SCAradomn = 100; 49 scia.setMinSampleDistance(SACdismin); 50 scia.setNumberOfSamples(SCANum); 51 scia.setCorrespondenceRandomness(SCAradomn); 52 53 PointCloud<PointXYZ> cloud_result; 54 Eigen::Matrix4f sac_trans; 55 scia.align(cloud_result); 56 sac_trans = scia.getFinalTransformation(); 57 58 // print log 59 std::cout << "[oneapi SCIA] Transformation Matrix 4x4 = " << std::endl << sac_trans << std::endl; 60}
Source the Intel® oneAPI Base Toolkit environment:
Build the code:
Run the binary:
Expected results example:
Code Explanation¶
Load source/target/fpfh_source/fpfh_target
PCD file
if (loadPCDFile<PointXYZ>("../../data/scia_source.pcd", cloud_source) < 0)
{
std::cerr << "Failed to read alignment source point cloud, please check scia_source.pcd" << std::endl;
return (-1);
}
if (loadPCDFile<PointXYZ>("../../data/scia_target.pcd", cloud_target) < 0)
{
std::cerr << "Failed to read alignment target point cloud, please check scia_target.pcd" << std::endl;
return (-1);
}
Load the example source/target/fpfh_source/fpfh_target
PCD into a PointCloud<PointXYZ/FPFHSignature33>
.
if (loadPCDFile<FPFHSignature33>("../../data/scia_source_fpfh33.pcd", FPFH_cloud_source) < 0)
{
std::cerr << "Failed to read FPFH feature cloud of alignment source point cloud, please check scia_source_fpfh33.pcd" << std::endl;
return (-1);
}
if (loadPCDFile<FPFHSignature33>("../../data/scia_target_fpfh33.pcd", FPFH_cloud_target) < 0)
{
std::cerr << "Failed to read FPFH feature cloud of alignment target point cloud, please check scia_target_fpfh33.pcd" << std::endl;
return (-1);
}
Start to compute the model.
// GPU calculate
pcl::oneapi::SampleConsensusInitialAlignment<PointXYZ, PointXYZ, FPFHSignature33> scia;
scia.setInputSource(cloud_source.makeShared());
scia.setInputTarget(cloud_target.makeShared());
scia.setSourceFeatures(FPFH_cloud_source.makeShared());
scia.setTargetFeatures(FPFH_cloud_target.makeShared());
constexpr float SACdismin = 0.02f;
constexpr int SCANum = 20;
constexpr int SCAradomn = 100;
scia.setMinSampleDistance(SACdismin);
scia.setNumberOfSamples(SCANum);
scia.setCorrespondenceRandomness(SCAradomn);
PointCloud<PointXYZ> cloud_result;
Eigen::Matrix4f sac_trans;
scia.align(cloud_result);
sac_trans = scia.getFinalTransformation();
Result(output log).