13 #ifndef RAIL_SEGMENTATION_SEGMENTER_H_ 14 #define RAIL_SEGMENTATION_SEGMENTER_H_ 23 #include <rail_manipulation_msgs/SegmentedObjectList.h> 24 #include <rail_manipulation_msgs/SegmentObjects.h> 25 #include <rail_segmentation/RemoveObject.h> 28 #include <sensor_msgs/Image.h> 30 #include <sensor_msgs/PointCloud2.h> 32 #include <std_srvs/Empty.h> 36 #include <visualization_msgs/Marker.h> 37 #include <visualization_msgs/MarkerArray.h> 40 #include <pcl/common/common.h> 41 #include <pcl/filters/conditional_removal.h> 42 #include <pcl/filters/extract_indices.h> 43 #include <pcl/filters/passthrough.h> 44 #include <pcl/filters/project_inliers.h> 45 #include <pcl/filters/voxel_grid.h> 46 #include <pcl/ModelCoefficients.h> 47 #include <pcl/point_types.h> 48 #include <pcl/point_cloud.h> 49 #include <pcl/segmentation/extract_clusters.h> 50 #include <pcl/segmentation/region_growing_rgb.h> 51 #include <pcl/segmentation/sac_segmentation.h> 55 #include <yaml-cpp/yaml.h> 58 #include <boost/thread/mutex.hpp> 66 namespace segmentation
79 #if __cplusplus >= 201103L 106 static const bool DEFAULT_DEBUG =
false;
108 static const double SAC_EPS_ANGLE = 0.15;
110 static const double SAC_DISTANCE_THRESHOLD = 0.01;
112 static const int SAC_MAX_ITERATIONS = 100;
114 static const double SURFACE_REMOVAL_PADDING = 0.005;
116 static const int DEFAULT_MIN_CLUSTER_SIZE = 200;
118 static const int DEFAULT_MAX_CLUSTER_SIZE = 10000;
120 static const double CLUSTER_TOLERANCE = 0.02;
122 static const double POINT_COLOR_THRESHOLD = 10;
124 static const double REGION_COLOR_THRESHOLD = 10;
126 static const float DOWNSAMPLE_LEAF_SIZE = 0.01;
128 static const double MARKER_SCALE = 0.01;
179 rail_segmentation::RemoveObject::Response &res);
191 bool clearCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
203 bool segmentCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
215 bool segmentObjectsCallback(rail_manipulation_msgs::SegmentObjects::Request &req, rail_manipulation_msgs::SegmentObjects::Response &res);
225 bool segmentObjects(rail_manipulation_msgs::SegmentedObjectList &objects);
241 rail_manipulation_msgs::SegmentedObject
findSurface(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
253 void extractClustersEuclidean(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
254 std::vector<pcl::PointIndices> &clusters)
const;
266 void extractClustersRGB(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
267 std::vector<pcl::PointIndices> &clusters)
const;
279 void inverseBound(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
280 const pcl::ConditionBase<pcl::PointXYZRGB>::Ptr &conditions,
const pcl::IndicesPtr &indices_out)
const;
291 void extract(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
292 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr &out)
const;
302 double averageZ(
const std::vector<pcl::PointXYZRGB, Eigen::aligned_allocator<pcl::PointXYZRGB> > &v)
const;
312 visualization_msgs::Marker
createMarker(
const pcl::PCLPointCloud2::ConstPtr &pc)
const;
323 sensor_msgs::Image
createImage(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
324 const pcl::PointIndices &cluster)
const;
351 pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr
pc_;
355 rail_manipulation_msgs::SegmentedObject
table_;
366 Eigen::Vector3f
RGB2Lab (
const Eigen::Vector3f& colorRGB);
const SegmentationZone & getCurrentZone() const
Determine the current zone based on the latest state of the TF tree.
bool segmentObjectsCallback(rail_manipulation_msgs::SegmentObjects::Request &req, rail_manipulation_msgs::SegmentObjects::Response &res)
Callback for the main segmentation request.
static const double POINT_COLOR_THRESHOLD
ros::ServiceServer remove_object_srv_
visualization_msgs::Marker table_marker_
rail_manipulation_msgs::SegmentedObjectList object_list_
void extract(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &out) const
Extract a new point cloud based on the given indices.
ros::Publisher debug_img_pub_
static const double SAC_EPS_ANGLE
ros::ServiceServer segment_objects_srv_
bool segmentCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Callback for the main segmentation request.
static const int DEFAULT_MAX_CLUSTER_SIZE
tf::TransformListener tf_
pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr pc_
ros::NodeHandle private_node_
The main grasp collector node object.
ros::Publisher table_pub_
void extractClustersRGB(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, std::vector< pcl::PointIndices > &clusters) const
Find clusters in a point cloud.
bool clearCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Callback for the clear request.
rail_manipulation_msgs::SegmentedObject findSurface(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const SegmentationZone &zone, const pcl::IndicesPtr &indices_out) const
Find and remove a surface from the given point cloud.
static const float DOWNSAMPLE_LEAF_SIZE
static const bool DEFAULT_DEBUG
bool segmentObjects(rail_manipulation_msgs::SegmentedObjectList &objects)
Callback for the main segmentation request.
visualization_msgs::MarkerArray markers_
static const double CLUSTER_TOLERANCE
static const double SURFACE_REMOVAL_PADDING
Segmenter()
Create a Segmenter and associated ROS information.
bool okay() const
A check for a valid Segmenter.
std::vector< SegmentationZone > zones_
bool removeObjectCallback(rail_segmentation::RemoveObject::Request &req, rail_segmentation::RemoveObject::Response &res)
Callback for the remove object request.
void pointCloudCallback(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &pc)
Callback for the point cloud topic.
static const int SAC_MAX_ITERATIONS
ros::Publisher markers_pub_
double averageZ(const std::vector< pcl::PointXYZRGB, Eigen::aligned_allocator< pcl::PointXYZRGB > > &v) const
Find the average Z value of the point vector.
ros::Publisher segmented_objects_pub_
static const int DEFAULT_MIN_CLUSTER_SIZE
tf2_ros::TransformListener tf2_
The criteria for a segmentation zone.
static const double REGION_COLOR_THRESHOLD
static const double MARKER_SCALE
ros::Publisher table_marker_pub_
static const double SAC_DISTANCE_THRESHOLD
void inverseBound(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const pcl::ConditionBase< pcl::PointXYZRGB >::Ptr &conditions, const pcl::IndicesPtr &indices_out) const
Bound a point cloud based on the inverse of a set of conditions.
Eigen::Vector3f RGB2Lab(const Eigen::Vector3f &colorRGB)
visualization_msgs::Marker createMarker(const pcl::PCLPointCloud2::ConstPtr &pc) const
Create a Marker from the given point cloud.
ros::Subscriber point_cloud_sub_
ros::Publisher debug_pc_pub_
rail_manipulation_msgs::SegmentedObject table_
ros::ServiceServer segment_srv_
The criteria for a segmentation zone.
ros::ServiceServer clear_srv_
void extractClustersEuclidean(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, std::vector< pcl::PointIndices > &clusters) const
Find clusters in a point cloud.
tf2_ros::Buffer tf_buffer_
sensor_msgs::Image createImage(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::PointIndices &cluster) const
Create a cropped image of the segmented object.