26 #include <dynamic_reconfigure/server.h> 27 #include <pcl/filters/filter.h> 28 #include <pcl/point_cloud.h> 29 #include <pcl/point_types.h> 30 #include <pcl/segmentation/sac_segmentation.h> 32 #include <pcl_msgs/ModelCoefficients.h> 33 #include <pcl_msgs/PointIndices.h> 35 #include <sensor_msgs/PointCloud2.h> 36 #include <velo2cam_calibration/PlaneConfig.h> 50 dynamic_reconfigure::Server<velo2cam_calibration::PlaneConfig>
server;
51 dynamic_reconfigure::Server<velo2cam_calibration::PlaneConfig>::CallbackType
55 cloud_sub = nh_.
subscribe<sensor_msgs::PointCloud2>(
57 inliers_pub = nh_.
advertise<pcl_msgs::PointIndices>(
"inliers", 1);
58 coeff_pub = nh_.
advertise<pcl_msgs::ModelCoefficients>(
"model", 1);
60 std::vector<double> axis_param;
61 Axis = Eigen::Vector3f::Zero();
65 if (axis_param.size() == 3) {
66 for (
int i = 0; i < 3; ++i) {
67 Axis[i] = axis_param[i];
75 nh_.
param(
"eps_angle", eps_angle_, 0.35);
79 nh_.
param(
"segmentation_type", sac_segmentation_type_, 0);
81 if (sac_segmentation_type_ == 0) {
82 ROS_INFO(
"Searching for planes perpendicular to %f %f %f", Axis[0],
85 ROS_INFO(
"Searching for planes parallel to %f %f %f", Axis[0], Axis[1],
90 server.setCallback(
f);
96 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
97 new pcl::PointCloud<pcl::PointXYZ>());
100 pcl::ModelCoefficients::Ptr coefficients(
new pcl::ModelCoefficients);
101 pcl::PointIndices::Ptr inliers(
new pcl::PointIndices);
103 pcl::SACSegmentation<pcl::PointXYZ> seg;
105 seg.setModelType(sac_segmentation_type_
106 ? pcl::SACMODEL_PARALLEL_PLANE
107 : pcl::SACMODEL_PERPENDICULAR_PLANE);
108 seg.setDistanceThreshold(threshold_);
109 seg.setMethodType(pcl::SAC_RANSAC);
111 seg.setOptimizeCoefficients(
true);
113 seg.setEpsAngle(eps_angle_);
114 seg.setMaxIterations(250);
116 std::vector<int> indices;
117 pcl::removeNaNFromPointCloud(*cloud, *cloud, indices);
119 seg.setInputCloud(cloud->makeShared());
120 seg.segment(*inliers, *coefficients);
122 if (inliers->indices.size() == 0) {
123 ROS_WARN(
"Could not estimate a planar model for the given dataset.");
127 pcl_msgs::PointIndices p_ind;
130 p_ind.header = input->header;
132 pcl_msgs::ModelCoefficients m_coeff;
135 m_coeff.header = input->header;
143 threshold_ = config.threshold;
144 ROS_INFO(
"New distance threshold: %f", threshold_);
148 int main(
int argc,
char **argv) {
149 ros::init(argc, argv,
"plane_segmentation");
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void cloud_callback(const sensor_msgs::PointCloud2::ConstPtr &input)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void param_callback(velo2cam_calibration::PlaneConfig &config, uint32_t level)
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
ROSCPP_DECL void spin(Spinner &spinner)
ros::Publisher inliers_pub
dynamic_reconfigure::Server< velo2cam_calibration::PlaneConfig > server
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int sac_segmentation_type_
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool getParam(const std::string &key, std::string &s) const
dynamic_reconfigure::Server< velo2cam_calibration::PlaneConfig >::CallbackType f
void moveFromPCL(pcl::PCLImage &pcl_image, sensor_msgs::Image &image)
ros::Subscriber cloud_sub