Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
doc
tutorials
content
sources
iccv2011
include
segmentation.h
1
#pragma once
2
3
#include "typedefs.h"
4
5
#include <pcl/ModelCoefficients.h>
6
#include <pcl/sample_consensus/method_types.h>
7
#include <pcl/sample_consensus/model_types.h>
8
#include <pcl/segmentation/sac_segmentation.h>
9
#include <pcl/filters/extract_indices.h>
10
#include <pcl/segmentation/extract_clusters.h>
11
12
13
/* Use SACSegmentation to find the dominant plane in the scene
14
* Inputs:
15
* input
16
* The input point cloud
17
* max_iterations
18
* The maximum number of RANSAC iterations to run
19
* distance_threshold
20
* The inlier/outlier threshold. Points within this distance
21
* from the hypothesized plane are scored as inliers.
22
* Return: A pointer to the ModelCoefficients (i.e., the 4 coefficients of the plane,
23
* represented in c0*x + c1*y + c2*z + c3 = 0 form)
24
*/
25
pcl::ModelCoefficients::Ptr
26
fitPlane (
const
PointCloudPtr & input,
float
distance_threshold,
float
max_iterations)
27
{
28
// Initialize the SACSegmentation object
29
pcl::SACSegmentation<PointT>
seg;
30
seg.
setOptimizeCoefficients
(
true
);
31
seg.
setModelType
(
pcl::SACMODEL_PLANE
);
32
seg.
setMethodType
(
pcl::SAC_RANSAC
);
33
seg.
setDistanceThreshold
(distance_threshold);
34
seg.
setMaxIterations
(max_iterations);
35
36
seg.
setInputCloud
(input);
37
pcl::ModelCoefficients::Ptr
coefficients (
new
pcl::ModelCoefficients
());
38
pcl::PointIndices::Ptr
inliers (
new
pcl::PointIndices
());
39
seg.
segment
(*inliers, *coefficients);
40
41
return
(coefficients);
42
}
43
44
/* Use SACSegmentation and an ExtractIndices filter to find the dominant plane and subtract it
45
* Inputs:
46
* input
47
* The input point cloud
48
* max_iterations
49
* The maximum number of RANSAC iterations to run
50
* distance_threshold
51
* The inlier/outlier threshold. Points within this distance
52
* from the hypothesized plane are scored as inliers.
53
* Return: A pointer to a new point cloud which contains only the non-plane points
54
*/
55
PointCloudPtr
56
findAndSubtractPlane (
const
PointCloudPtr & input,
float
distance_threshold,
float
max_iterations)
57
{
58
// Find the dominant plane
59
pcl::SACSegmentation<PointT>
seg;
60
seg.
setOptimizeCoefficients
(
false
);
61
seg.
setModelType
(
pcl::SACMODEL_PLANE
);
62
seg.
setMethodType
(
pcl::SAC_RANSAC
);
63
seg.
setDistanceThreshold
(distance_threshold);
64
seg.
setMaxIterations
(max_iterations);
65
seg.
setInputCloud
(input);
66
pcl::ModelCoefficients::Ptr
coefficients (
new
pcl::ModelCoefficients
());
67
pcl::PointIndices::Ptr
inliers (
new
pcl::PointIndices
());
68
seg.
segment
(*inliers, *coefficients);
69
70
// Extract the inliers
71
pcl::ExtractIndices<PointT>
extract;
72
extract.
setInputCloud
(input);
73
extract.
setIndices
(inliers);
74
extract.
setNegative
(
true
);
75
PointCloudPtr output (
new
PointCloud);
76
extract.
filter
(*output);
77
78
return
(output);
79
}
80
81
/* Use EuclidieanClusterExtraction to group a cloud into contiguous clusters
82
* Inputs:
83
* input
84
* The input point cloud
85
* cluster_tolerance
86
* The maximum distance between neighboring points in a cluster
87
* min/max_cluster_size
88
* The minimum and maximum allowable cluster sizes
89
* Return (by reference): a vector of PointIndices containing the points indices in each cluster
90
*/
91
void
92
clusterObjects (
const
PointCloudPtr & input,
93
float
cluster_tolerance,
int
min_cluster_size,
int
max_cluster_size,
94
std::vector<pcl::PointIndices> & cluster_indices_out)
95
{
96
pcl::EuclideanClusterExtraction<PointT>
ec;
97
ec.
setClusterTolerance
(cluster_tolerance);
98
ec.
setMinClusterSize
(min_cluster_size);
99
ec.
setMaxClusterSize
(max_cluster_size);
100
101
ec.
setInputCloud
(input);
102
ec.
extract
(cluster_indices_out);
103
}
pcl::EuclideanClusterExtraction
EuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sen...
Definition
extract_clusters.h:328
pcl::EuclideanClusterExtraction::extract
void extract(std::vector< PointIndices > &clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>.
Definition
extract_clusters.hpp:224
pcl::EuclideanClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
extract_clusters.h:368
pcl::EuclideanClusterExtraction::setMaxClusterSize
void setMaxClusterSize(pcl::uindex_t max_cluster_size)
Set the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition
extract_clusters.h:400
pcl::EuclideanClusterExtraction::setMinClusterSize
void setMinClusterSize(pcl::uindex_t min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition
extract_clusters.h:384
pcl::ExtractIndices
ExtractIndices extracts a set of indices from a point cloud.
Definition
extract_indices.h:70
pcl::FilterIndices::filter
void filter(Indices &indices)
Calls the filtering method and returns the filtered point cloud indices.
Definition
filter_indices.h:100
pcl::FilterIndices::setNegative
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions.
Definition
filter_indices.h:115
pcl::PCLBase::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition
pcl_base.hpp:65
pcl::PCLBase::setIndices
virtual void setIndices(const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
Definition
pcl_base.hpp:72
pcl::SACSegmentation
SACSegmentation represents the Nodelet segmentation class for Sample Consensus methods and models,...
Definition
sac_segmentation.h:65
pcl::SACSegmentation::setMethodType
void setMethodType(int method)
The type of sample consensus method to use (user given parameter).
Definition
sac_segmentation.h:113
pcl::SACSegmentation::setMaxIterations
void setMaxIterations(int max_iterations)
Set the maximum number of iterations before giving up.
Definition
sac_segmentation.h:133
pcl::SACSegmentation::segment
virtual void segment(PointIndices &inliers, ModelCoefficients &model_coefficients)
Base method for segmentation of a model in a PointCloud given by <setInputCloud (),...
Definition
sac_segmentation.hpp:80
pcl::SACSegmentation::setModelType
void setModelType(int model)
The type of model to use (user given parameter).
Definition
sac_segmentation.h:95
pcl::SACSegmentation::setDistanceThreshold
void setDistanceThreshold(double threshold)
Distance to the model threshold (user given parameter).
Definition
sac_segmentation.h:123
pcl::SACSegmentation::setOptimizeCoefficients
void setOptimizeCoefficients(bool optimize)
Set to true if a coefficient refinement is required.
Definition
sac_segmentation.h:160
pcl::SAC_RANSAC
constexpr int SAC_RANSAC
Definition
method_types.h:45
pcl::SACMODEL_PLANE
@ SACMODEL_PLANE
Definition
model_types.h:47
pcl::ModelCoefficients
Definition
ModelCoefficients.h:12
pcl::ModelCoefficients::Ptr
shared_ptr< ::pcl::ModelCoefficients > Ptr
Definition
ModelCoefficients.h:20
pcl::PointIndices
Definition
PointIndices.h:12
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition
PointIndices.h:13