Skip to content

Commit 45554c7

Browse files
committed
add StatisticalOutlierFilter
1 parent 73ad830 commit 45554c7

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

pcl.pyx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ cdef class PointCloud:
249249

250250
return seg
251251

252+
def make_statistical_outlier_filter(self):
253+
"""
254+
Return a pcl.StatisticalOutlierRemovalFilter object with this object set as the input-cloud
255+
"""
256+
fil = StatisticalOutlierRemovalFilter()
257+
cdef cpp.StatisticalOutlierRemoval_t *cfil = <cpp.StatisticalOutlierRemoval_t *>fil.me
258+
cdef cpp.PointCloud_t *ccloud = <cpp.PointCloud_t *>self.thisptr
259+
cfil.setInputCloud(ccloud.makeShared())
260+
return fil
261+
252262
def filter_mls(self, double searchRadius, bool polynomialFit=True, int polynomialOrder=2):
253263
"""
254264
Perform a Moving Least Squares filter on this cloud and return the
@@ -290,3 +300,42 @@ cdef class PointCloud:
290300

291301
return pycloud
292302

303+
cdef class StatisticalOutlierRemovalFilter:
304+
"""
305+
Filter class uses point neighborhood statistics to filter outlier data.
306+
"""
307+
cdef cpp.StatisticalOutlierRemoval_t *me
308+
def __cinit__(self):
309+
self.me = new cpp.StatisticalOutlierRemoval_t()
310+
def __dealloc__(self):
311+
del self.me
312+
313+
def set_mean_k(self, int k):
314+
"""
315+
Set the number of points (k) to use for mean distance estimation.
316+
"""
317+
self.me.setMeanK(k)
318+
319+
def set_std_dev_mul_thresh(self, double std_mul):
320+
"""
321+
Set the standard deviation multiplier threshold.
322+
"""
323+
self.me.setStddevMulThresh(std_mul)
324+
325+
def set_negative(self, bool negative):
326+
"""
327+
Set whether the indices should be returned, or all points except the indices.
328+
"""
329+
self.me.setNegative(negative)
330+
331+
def filter(self):
332+
"""
333+
Apply the filter according to the previously set parameters and return
334+
a new pointcloud
335+
"""
336+
pc = PointCloud()
337+
cdef cpp.PointCloud_t *ccloud = <cpp.PointCloud_t *>pc.thisptr
338+
self.me.filter(deref(ccloud))
339+
return pc
340+
341+

pcl_defs.pxd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,14 @@ ctypedef PointCloud[PointXYZ] PointCloud_t
133133
ctypedef PointCloud[Normal] PointNormalCloud_t
134134
ctypedef shared_ptr[PointCloud[PointXYZ]] PointCloudPtr_t
135135

136+
cdef extern from "pcl/filters/statistical_outlier_removal.h" namespace "pcl":
137+
cdef cppclass StatisticalOutlierRemoval[T]:
138+
StatisticalOutlierRemoval()
139+
void setMeanK (int nr_k)
140+
void setStddevMulThresh (double std_mul)
141+
void setNegative (bool negative)
142+
void setInputCloud (shared_ptr[PointCloud[T]])
143+
void filter(PointCloud[T] c)
144+
145+
ctypedef StatisticalOutlierRemoval[PointXYZ] StatisticalOutlierRemoval_t
146+

tests/test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,30 @@ def testExtractNeg(self):
204204
self.assertNotEqual(self.p, p2)
205205
self.assertEqual(p2.size, self.p.size - 3)
206206

207+
class TestSegmenterNormal(unittest.TestCase):
208+
209+
def setUp(self):
210+
self.p = pcl.PointCloud()
211+
self.p.from_file("tests/table_scene_mug_stereo_textured_noplane.pcd")
212+
213+
def testFilterPos(self):
214+
fil = self.p.make_statistical_outlier_filter()
215+
fil.set_mean_k (50)
216+
fil.set_std_dev_mul_thresh (1.0)
217+
c = fil.filter()
218+
self.assertEqual(c.size, 22747)
219+
self.assertEqual(c.width, 22747)
220+
self.assertEqual(c.height, 1)
221+
self.assertTrue(c.is_dense)
222+
223+
def testFilterNeg(self):
224+
fil = self.p.make_statistical_outlier_filter()
225+
fil.set_mean_k (50)
226+
fil.set_std_dev_mul_thresh (1.0)
227+
fil.set_negative(True)
228+
c = fil.filter()
229+
self.assertEqual(c.size, 1013)
230+
self.assertEqual(c.width, 1013)
231+
self.assertEqual(c.height, 1)
232+
self.assertTrue(c.is_dense)
207233

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy