Plane Model Segmentation¶
In this tutorial we will learn how to do a simple plane segmentation from a set of points to find all the points within a point cloud that support a plane model.
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_passthrough.cpp
should be in the directory with following content:1#include <pcl/oneapi/segmentation/segmentation.h> 2#include <pcl/io/pcd_io.h> 3#include <pcl/point_types.h> 4 5int main (int argc, char **argv) 6{ 7 std::cout << "Running on device: " << dpct::get_default_queue().get_device().get_info<sycl::info::device::name>() << "\n"; 8 9 //Read Point Cloud 10 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_input (new pcl::PointCloud<pcl::PointXYZ> ()); 11 12 //Load a standard PCD file from disk 13 int result = pcl::io::loadPCDFile("test59.pcd", *cloud_input); 14 if (result != 0) 15 { 16 pcl::console::print_info ("Load pcd file failed.\n"); 17 return result; 18 } 19 20 //Create the oneapi_segmentation object 21 pcl::oneapi::SACSegmentation seg; 22 23 //Configure oneapi_segmentation class 24 seg.setInputCloud(cloud_input); 25 seg.setProbability(0.99); 26 seg.setMaxIterations(50); 27 seg.setDistanceThreshold(0.01); 28 //Optional 29 seg.setOptimizeCoefficients(true); 30 //Set algorithm method and model type 31 seg.setMethodType(pcl::oneapi::SAC_RANSAC); 32 seg.setModelType (pcl::oneapi::SACMODEL_PLANE); 33 34 //Out parameter declaration for getting inliers and model coefficients 35 pcl::PointIndices::Ptr inliers (new pcl::PointIndices); 36 double coeffs[4]={0,0,0,0}; 37 38 //Getting inliers and model coefficients 39 seg.segment(*inliers, coeffs); 40 41 std::cout << "input cloud size : " << seg.getCloudSize() << std::endl; 42 std::cout << "inliers size : " << seg.getInliersSize() << std::endl; 43 std::cout << "model coefficients : " << coeffs[0] << ", " << coeffs[1] << ", " << coeffs[2] << ", " << coeffs[3] << std::endl; 44 45 return 0; 46}
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¶
Load the test data from GitHub* into a PointCloud<PointXYZ>.
Create the oneapi_segmentation object.
Configure the oneapi_segmentation class.
Set to true if a coefficient refinement is required.
Set the algorithm method and model type.
Declare output parameters for getting inliers and model coefficients.
Get inliers and model coefficients by calling the segment() API.
Result (output log):