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?