This repository was archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathfilter_objects.py
More file actions
executable file
·50 lines (35 loc) · 1.93 KB
/
filter_objects.py
File metadata and controls
executable file
·50 lines (35 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pcl
# Returns Downsampled version of a point cloud
# The bigger the leaf size the less information retained
def do_voxel_grid_filter(point_cloud, LEAF_SIZE = 0.01):
voxel_filter = point_cloud.make_voxel_grid_filter()
voxel_filter.set_leaf_size(LEAF_SIZE, LEAF_SIZE, LEAF_SIZE)
return voxel_filter.filter()
# Returns only the point cloud information at a specific range of a specific axis
def do_passthrough_filter(point_cloud, name_axis = 'z', min_axis = 0.6, max_axis = 1.1):
pass_filter = point_cloud.make_passthrough_filter()
pass_filter.set_filter_field_name(name_axis);
pass_filter.set_filter_limits(min_axis, max_axis)
return pass_filter.filter()
# Use RANSAC planse segmentation to separate plane and not plane points
# Returns inliers (plane) and outliers (not plane)
def do_ransac_plane_segmentation(point_cloud, max_distance = 0.01):
segmenter = point_cloud.make_segmenter()
segmenter.set_model_type(pcl.SACMODEL_PLANE)
segmenter.set_method_type(pcl.SAC_RANSAC)
segmenter.set_distance_threshold(max_distance)
#obtain inlier indices and model coefficients
inlier_indices, coefficients = segmenter.segment()
inliers = point_cloud.extract(inlier_indices, negative = False)
outliers = point_cloud.extract(inlier_indices, negative = True)
return inliers, outliers
##################################################################################
# This pipeline separates the objects in the table from the given scene
# Load the point cloud in memory
cloud = pcl.load_XYZRGB('point_clouds/tabletop.pcd')
# Get only information in our region of interest, as we don't care about the other parts
filtered_cloud = do_passthrough_filter(point_cloud = cloud,
name_axis = 'z', min_axis = 0.6, max_axis = 1.1)
# Separate the table from everything else
table_cloud, objects_cloud = do_ransac_plane_segmentation(filtered_cloud, max_distance = 0.01)
pcl.save(objects_cloud, 'objects.pcd');