MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / maskForegroundPoints

Function maskForegroundPoints

tools/train_linemod_template.cpp:102–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101
102std::vector<bool>
103maskForegroundPoints (const PointCloudXYZRGBA::ConstPtr & input,
104 float min_depth, float max_depth, float max_height)
105{
106 std::vector<bool> foreground_mask (input->size (), false);
107
108 // Mask off points outside the specified near and far depth thresholds
109 pcl::IndicesPtr indices (new pcl::Indices);
110 for (std::size_t i = 0; i < input->size (); ++i)
111 {
112 const float z = (*input)[i].z;
113 if (min_depth < z && z < max_depth)
114 {
115 foreground_mask[i] = true;
116 indices->push_back (static_cast<int> (i));
117 }
118 }
119
120 // Find the dominant plane between the specified near/far thresholds
121 constexpr float distance_threshold = 0.02f;
122 constexpr int max_iterations = 500;
123 pcl::SACSegmentation<pcl::PointXYZRGBA> seg;
124 seg.setOptimizeCoefficients (true);
125 seg.setModelType (pcl::SACMODEL_PLANE);
126 seg.setMethodType (pcl::SAC_RANSAC);
127 seg.setDistanceThreshold (distance_threshold);
128 seg.setMaxIterations (max_iterations);
129 seg.setInputCloud (input);
130 seg.setIndices (indices);
131 pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
132 pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
133 seg.segment (*inliers, *coefficients);
134
135 // Mask off the plane inliers
136 for (const auto &index : inliers->indices)
137 foreground_mask[index] = false;
138
139 // Mask off any foreground points that are too high above the detected plane
140 const std::vector<float> & c = coefficients->values;
141 for (std::size_t i = 0; i < input->size (); ++i)
142 {
143 if (foreground_mask[i])
144 {
145 const pcl::PointXYZRGBA & p = (*input)[i];
146 float d = std::abs (c[0]*p.x + c[1]*p.y + c[2]*p.z + c[3]);
147 foreground_mask[i] = (d < max_height);
148 }
149 }
150
151 return (foreground_mask);
152}
153
154void
155trainTemplate (const PointCloudXYZRGBA::ConstPtr & input, const std::vector<bool> &foreground_mask,

Callers 1

computeFunction · 0.85

Calls 11

absFunction · 0.85
setMethodTypeMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45
setModelTypeMethod · 0.45
setDistanceThresholdMethod · 0.45
setMaxIterationsMethod · 0.45
setInputCloudMethod · 0.45
setIndicesMethod · 0.45
segmentMethod · 0.45

Tested by

no test coverage detected