13 #ifndef RAIL_SEGMENTATION_SEGMENTER_H_ 14 #define RAIL_SEGMENTATION_SEGMENTER_H_ 23 #include <rail_manipulation_msgs/ProcessSegmentedObjects.h> 24 #include <rail_manipulation_msgs/SegmentedObjectList.h> 25 #include <rail_manipulation_msgs/SegmentObjects.h> 26 #include <rail_manipulation_msgs/SegmentObjectsFromPointCloud.h> 27 #include <rail_segmentation/RemoveObject.h> 30 #include <sensor_msgs/Image.h> 32 #include <sensor_msgs/PointCloud2.h> 34 #include <std_srvs/Empty.h> 38 #include <visualization_msgs/Marker.h> 39 #include <visualization_msgs/MarkerArray.h> 42 #include <pcl/common/common.h> 43 #include <pcl/filters/conditional_removal.h> 44 #include <pcl/filters/extract_indices.h> 45 #include <pcl/filters/passthrough.h> 46 #include <pcl/filters/project_inliers.h> 47 #include <pcl/filters/voxel_grid.h> 48 #include <pcl/ModelCoefficients.h> 49 #include <pcl/point_types.h> 50 #include <pcl/point_cloud.h> 51 #include <pcl/segmentation/extract_clusters.h> 52 #include <pcl/segmentation/region_growing_rgb.h> 53 #include <pcl/segmentation/sac_segmentation.h> 57 #include <yaml-cpp/yaml.h> 60 #include <boost/thread/mutex.hpp> 68 namespace segmentation
81 #if __cplusplus >= 201103L 108 static const bool DEFAULT_DEBUG =
false;
110 static const double SAC_EPS_ANGLE = 0.15;
112 static const double SAC_DISTANCE_THRESHOLD = 0.01;
114 static const int SAC_MAX_ITERATIONS = 100;
116 static const double SURFACE_REMOVAL_PADDING = 0.005;
118 static const int DEFAULT_MIN_CLUSTER_SIZE = 200;
120 static const int DEFAULT_MAX_CLUSTER_SIZE = 10000;
122 static const double CLUSTER_TOLERANCE = 0.02;
124 static const double POINT_COLOR_THRESHOLD = 10;
126 static const double REGION_COLOR_THRESHOLD = 10;
128 static const float DOWNSAMPLE_LEAF_SIZE = 0.01;
130 static const double MARKER_SCALE = 0.01;
172 rail_segmentation::RemoveObject::Response &res);
184 bool clearCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
196 bool segmentCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res);
199 rail_manipulation_msgs::ProcessSegmentedObjects::Response &res);
211 bool segmentObjectsCallback(rail_manipulation_msgs::SegmentObjects::Request &req, rail_manipulation_msgs::SegmentObjects::Response &res);
223 bool segmentObjectsFromPointCloudCallback(rail_manipulation_msgs::SegmentObjectsFromPointCloud::Request &req, rail_manipulation_msgs::SegmentObjectsFromPointCloud::Response &res);
233 bool segmentObjects(rail_manipulation_msgs::SegmentedObjectList &objects);
241 rail_manipulation_msgs::SegmentedObjectList &objects);
258 bool findSurface(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
260 rail_manipulation_msgs::SegmentedObject &table_out)
const;
271 void extractClustersEuclidean(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
272 std::vector<pcl::PointIndices> &clusters)
const;
284 void extractClustersRGB(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
285 std::vector<pcl::PointIndices> &clusters)
const;
297 void inverseBound(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
298 const pcl::ConditionBase<pcl::PointXYZRGB>::Ptr &conditions,
const pcl::IndicesPtr &indices_out)
const;
309 void extract(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
const pcl::IndicesConstPtr &indices_in,
310 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr &out)
const;
320 double averageZ(
const std::vector<pcl::PointXYZRGB, Eigen::aligned_allocator<pcl::PointXYZRGB> > &v)
const;
330 visualization_msgs::Marker
createMarker(
const pcl::PCLPointCloud2::ConstPtr &pc)
const;
341 sensor_msgs::Image
createImage(
const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &in,
342 const pcl::PointIndices &cluster)
const;
379 rail_manipulation_msgs::SegmentedObject
table_;
392 Eigen::Vector3f
RGB2Lab (
const Eigen::Vector3f& colorRGB);
std::string point_cloud_topic_
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_
bool executeSegmentation(pcl::PointCloud< pcl::PointXYZRGB >::Ptr pc, rail_manipulation_msgs::SegmentedObjectList &objects)
Main segmentation routine.
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.
visualization_msgs::Marker table_marker_
rail_manipulation_msgs::SegmentedObjectList object_list_
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.
ros::Publisher debug_img_pub_
static const double SAC_EPS_ANGLE
visualization_msgs::Marker createMarker(const pcl::PCLPointCloud2::ConstPtr &pc) const
Create a Marker from the given point cloud.
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_
ros::NodeHandle private_node_
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.
The main grasp collector node object.
ros::Publisher table_pub_
bool clearCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Callback for the clear request.
static const float DOWNSAMPLE_LEAF_SIZE
bool okay() const
A check for a valid Segmenter.
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 SURFACE_REMOVAL_PADDING
Segmenter()
Create a Segmenter and associated ROS information.
const SegmentationZone & getCurrentZone() const
Determine the current zone based on the latest state of the TF tree.
std::vector< SegmentationZone > zones_
double averageZ(const std::vector< pcl::PointXYZRGB, Eigen::aligned_allocator< pcl::PointXYZRGB > > &v) const
Find the average Z value of the point vector.
bool removeObjectCallback(rail_segmentation::RemoveObject::Request &req, rail_segmentation::RemoveObject::Response &res)
Callback for the remove object request.
static const int SAC_MAX_ITERATIONS
ros::Publisher markers_pub_
ros::Publisher segmented_objects_pub_
static const int DEFAULT_MIN_CLUSTER_SIZE
visualization_msgs::MarkerArray text_markers_
bool calculateFeaturesCallback(rail_manipulation_msgs::ProcessSegmentedObjects::Request &req, rail_manipulation_msgs::ProcessSegmentedObjects::Response &res)
tf2_ros::TransformListener tf2_
The criteria for a segmentation zone.
ros::ServiceServer calculate_features_srv_
static const double REGION_COLOR_THRESHOLD
static const double MARKER_SCALE
bool segmentObjectsFromPointCloudCallback(rail_manipulation_msgs::SegmentObjectsFromPointCloud::Request &req, rail_manipulation_msgs::SegmentObjectsFromPointCloud::Response &res)
Callback for the main segmentation request.
ros::ServiceServer segment_objects_from_point_cloud_srv_
static const double CLUSTER_TOLERANCE
ros::Publisher table_marker_pub_
static const double SAC_DISTANCE_THRESHOLD
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.
Eigen::Vector3f RGB2Lab(const Eigen::Vector3f &colorRGB)
sensor_msgs::Image createImage(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::PointIndices &cluster) const
Create a cropped image of the segmented object.
ros::Publisher debug_pc_pub_
rail_manipulation_msgs::SegmentedObject table_
bool findSurface(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &in, const pcl::IndicesConstPtr &indices_in, const SegmentationZone &zone, const pcl::IndicesPtr &indices_out, rail_manipulation_msgs::SegmentedObject &table_out) const
Find and remove a surface from the given point cloud.
ros::ServiceServer segment_srv_
double cluster_tolerance_
The criteria for a segmentation zone.
ros::ServiceServer clear_srv_
tf2_ros::Buffer tf_buffer_