Euclidean-PCL-Cpp (70%)

์ฝ”๋“œ๋Š” [์ด๊ณณ]์—์„œ ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ƒ˜ํ”ŒํŒŒ์ผ์€ [RANSAC_plane_true.pcd]์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

#include <pcl/ModelCoefficients.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d.h>
#include <pcl/kdtree/kdtree.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>

// Euclidean Cluster Extraction
// http://pointclouds.org/documentation/tutorials/cluster_extraction.php#cluster-extraction

int 
main (int argc, char** argv)
{

  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_f (new pcl::PointCloud<pcl::PointXYZRGB>);

  // *.PCD ํŒŒ์ผ ์ฝ๊ธฐ (https://raw.githubusercontent.com/adioshun/gitBook_Tutorial_PCL/master/Intermediate/sample/RANSAC_plane_true.pcd)
  pcl::io::loadPCDFile<pcl::PointXYZRGB> ("RANSAC_plane_true.pcd", *cloud);

  // ํฌ์ธํŠธ์ˆ˜ ์ถœ๋ ฅ
  std::cout << "PointCloud before filtering has: " << cloud->points.size () << " data points." << std::endl; //*

  // ํƒ์ƒ‰์„ ์œ„ํ•œ KdTree ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ //Creating the KdTree object for the search method of the extraction
  pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB>);
  tree->setInputCloud (cloud);  //KdTree ์ƒ์„ฑ 


  std::vector<pcl::PointIndices> cluster_indices;       // ๊ตฐ์ง‘ํ™”๋œ ๊ฒฐ๊ณผ๋ฌผ์˜ Index ์ €์žฅ, ๋‹ค์ค‘ ๊ตฐ์ง‘ํ™” ๊ฐ์ฒด๋Š” cluster_indices[0] ์ˆœ์œผ๋กœ ์ €์žฅ 
  // ๊ตฐ์ง‘ํ™” ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ  
  pcl::EuclideanClusterExtraction<pcl::PointXYZRGB> ec;
  ec.setInputCloud (cloud);       // ์ž…๋ ฅ   
  ec.setClusterTolerance (0.02);  // 2cm  
  ec.setMinClusterSize (100);     // ์ตœ์†Œ ํฌ์ธํŠธ ์ˆ˜ 
  ec.setMaxClusterSize (25000);   // ์ตœ๋Œ€ ํฌ์ธํŠธ ์ˆ˜
  ec.setSearchMethod (tree);      // ์œ„์—์„œ ์ •์˜ํ•œ ํƒ์ƒ‰ ๋ฐฉ๋ฒ• ์ง€์ • 
  ec.extract (cluster_indices);   // ๊ตฐ์ง‘ํ™” ์ ์šฉ 

  // ํด๋Ÿฌ์Šคํ„ฐ๋ณ„ ์ •๋ณด ์ˆ˜์ง‘, ์ถœ๋ ฅ, ์ €์žฅ 
  int j = 0;
  for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it)
  {
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster (new pcl::PointCloud<pcl::PointXYZRGB>);
    for (std::vector<int>::const_iterator pit = it->indices.begin (); pit != it->indices.end (); ++pit)
     cloud_cluster->points.push_back (cloud->points[*pit]); 
    cloud_cluster->width = cloud_cluster->points.size ();
    cloud_cluster->height = 1;
    cloud_cluster->is_dense = true;

    // ํฌ์ธํŠธ์ˆ˜ ์ถœ๋ ฅ
    std::cout << "PointCloud representing the Cluster: " << cloud_cluster->points.size () << " data points." << std::endl;

    // ํด๋Ÿฌ์Šคํ„ฐ๋ณ„ ์ด๋ฆ„ ์ƒ์„ฑ ๋ฐ ์ €์žฅ 
    std::stringstream ss;
    ss << "cloud_cluster_" << j << ".pcd";
    pcl::PCDWriter writer;
    writer.write<pcl::PointXYZRGB> (ss.str (), *cloud_cluster, false); //*
    j++;
  }

  return (0);
}

์‹คํ–‰ & ๊ฒฐ๊ณผ

$ PointCloud before filtering has: 23330 data points.
$ PointCloud representing the Cluster: 5981 data points.
$ PointCloud representing the Cluster: 5111 data points.
$ PointCloud representing the Cluster: 4431 data points.
$ PointCloud representing the Cluster: 2768 data points.
$ PointCloud representing the Cluster: 2513 data points.
$ PointCloud representing the Cluster: 1552 data points.
$ PointCloud representing the Cluster: 934 data points.

์‹œ๊ฐํ™” & ๊ฒฐ๊ณผ

$ pcl_viewer cloud_cluster_0.pcd 
$ pcl_viewer cloud_cluster_6.pcd

์›๋ณธ(RANSAC_plane_true.pcd)

๊ฒฐ๊ณผ(cloud_cluster_0.pcd)

๊ฒฐ๊ณผ(cloud_cluster_6.pcd)

  • Adaptive clustering: Online learning for human classification in 3D LiDAR-based tracking(2017) ์—์„œ ํ™œ์šฉํ•œ Euclidean clustering ๊ธฐ๋ฒ•

Last updated

Was this helpful?