border_estimator_nodelet.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2014, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #define BOOST_PARAMETER_MAX_ARITY 7
38 #include <pcl/range_image/range_image_planar.h>
39 #include <pcl/range_image/range_image_spherical.h>
41 #include <cv_bridge/cv_bridge.h>
43 
44 namespace jsk_pcl_ros
45 {
47  {
48  ConnectionBasedNodelet::onInit();
49  // planar or spherical
50  pnh_->param("model_type", model_type_, std::string("planar"));
51  srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
52  typename dynamic_reconfigure::Server<Config>::CallbackType f =
53  boost::bind (&BorderEstimator::configCallback, this, _1, _2);
54  srv_->setCallback (f);
55 
56  pub_border_ = advertise<PCLIndicesMsg>(*pnh_, "output_border_indices", 1);
57  pub_veil_ = advertise<PCLIndicesMsg>(*pnh_, "output_veil_indices", 1);
58  pub_shadow_ = advertise<PCLIndicesMsg>(*pnh_, "output_shadow_indices", 1);
59  pub_range_image_ = advertise<sensor_msgs::Image>(
60  *pnh_, "output_range_image", 1);
61  pub_cloud_ = advertise<sensor_msgs::PointCloud2>(
62  *pnh_, "output_cloud", 1);
63 
64  onInitPostProcess();
65  }
66 
68  // message_filters::Synchronizer needs to be called reset
69  // before message_filters::Subscriber is freed.
70  // Calling reset fixes the following error on shutdown of the nodelet:
71  // terminate called after throwing an instance of
72  // 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
73  // what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argument
74  // Also see https://github.com/ros/ros_comm/issues/720 .
75  sync_.reset();
76  }
77 
79  {
80  if (model_type_ == "planar") {
81  sub_point_.subscribe(*pnh_, "input", 1);
82  sub_camera_info_.subscribe(*pnh_, "input_camera_info", 1);
83  sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(100);
84  sync_->connectInput(sub_point_, sub_camera_info_);
85  sync_->registerCallback(boost::bind(&BorderEstimator::estimate, this, _1, _2));
86  }
87  else if (model_type_ == "laser") {
88  sub_ = pnh_->subscribe("input", 1, &BorderEstimator::estimate, this);
89  }
90  }
91 
93  {
94  if (model_type_ == "planar") {
97  }
98  else if (model_type_ == "laser") {
99  sub_.shutdown();
100  }
101  }
102 
105  const pcl::PointIndices& inlier,
106  const std_msgs::Header& header)
107  {
109  msg.header = header;
110  msg.indices = inlier.indices;
111  pub.publish(msg);
112  }
113 
115  const sensor_msgs::PointCloud2::ConstPtr& msg)
116  {
117  boost::mutex::scoped_lock lock(mutex_);
118  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
120  pcl::RangeImage range_image;
121  if (model_type_ == "sphere") {
122  range_image = pcl::RangeImageSpherical();
123  }
124  range_image.createFromPointCloud(
125  *cloud,
128  Eigen::Affine3f::Identity(),
129  pcl::RangeImage::CAMERA_FRAME,
130  noise_level_,
131  min_range_,
132  border_size_);
133  range_image.setUnseenToMaxRange();
134  computeBorder(range_image, msg->header);
135  }
136 
138  const pcl::RangeImage& range_image,
139  const std_msgs::Header& header)
140  {
141  pcl::RangeImageBorderExtractor border_extractor (&range_image);
142  pcl::PointCloud<pcl::BorderDescription> border_descriptions;
143  border_extractor.compute (border_descriptions);
144  pcl::PointIndices border_indices, veil_indices, shadow_indices;
145  for (int y = 0; y < (int)range_image.height; ++y) {
146  for (int x = 0; x < (int)range_image.width; ++x) {
147  if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__OBSTACLE_BORDER]) {
148  border_indices.indices.push_back (y*range_image.width + x);
149  }
150  if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__VEIL_POINT]) {
151  veil_indices.indices.push_back (y*range_image.width + x);
152  }
153  if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__SHADOW_BORDER]) {
154  shadow_indices.indices.push_back (y*range_image.width + x);
155  }
156  }
157  }
158  publishCloud(pub_border_, border_indices, header);
159  publishCloud(pub_veil_, veil_indices, header);
160  publishCloud(pub_shadow_, shadow_indices, header);
161  cv::Mat image;
162  jsk_recognition_utils::rangeImageToCvMat(range_image, image);
166  image).toImageMsg());
167  // publish pointcloud
168  sensor_msgs::PointCloud2 ros_cloud;
169  pcl::toROSMsg(range_image, ros_cloud);
170  ros_cloud.header = header;
171  pub_cloud_.publish(ros_cloud);
172  }
173 
175  const sensor_msgs::PointCloud2::ConstPtr& msg,
176  const sensor_msgs::CameraInfo::ConstPtr& info)
177  {
178  if (msg->height == 1) {
179  NODELET_ERROR("[BorderEstimator::estimate] pointcloud must be organized");
180  return;
181  }
182  pcl::RangeImagePlanar range_image;
183  pcl::PointCloud<pcl::PointXYZ> cloud;
185  Eigen::Affine3f dummytrans = Eigen::Affine3f::Identity();
186  float fx = info->P[0];
187  float cx = info->P[2];
188  float tx = info->P[3];
189  float fy = info->P[5];
190  float cy = info->P[6];
191  range_image.createFromPointCloudWithFixedSize (cloud,
192  msg->width,
193  msg->height,
194  cx, cy,
195  fx, fy,
196  dummytrans);
197  range_image.setUnseenToMaxRange();
198  computeBorder(range_image, msg->header);
199  }
200 
201  void BorderEstimator::configCallback(Config &config, uint32_t level)
202  {
203  boost::mutex::scoped_lock lock(mutex_);
204  noise_level_ = config.noise_level;
205  min_range_ = config.min_range;
206  border_size_ = config.border_size;
207  angular_resolution_ = config.angular_resolution;
208  max_angle_height_ = config.max_angle_height;
209  max_angle_width_ = config.max_angle_width;
210  }
211 }
212 
jsk_pcl_ros::BorderEstimator::subscribe
virtual void subscribe()
Definition: border_estimator_nodelet.cpp:78
NODELET_ERROR
#define NODELET_ERROR(...)
jsk_pcl_ros::BorderEstimator::pub_veil_
ros::Publisher pub_veil_
Definition: border_estimator.h:149
depth_error_calibration.lock
lock
Definition: depth_error_calibration.py:32
ros::Publisher
_2
boost::arg< 2 > _2
image_encodings.h
jsk_pcl_ros::BorderEstimator::pub_range_image_
ros::Publisher pub_range_image_
Definition: border_estimator.h:150
sample_simulate_tabletop_cloud.header
header
Definition: sample_simulate_tabletop_cloud.py:162
jsk_pcl_ros::BorderEstimator::sub_
ros::Subscriber sub_
Definition: border_estimator.h:152
jsk_pcl_ros::BorderEstimator::srv_
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
Definition: border_estimator.h:148
jsk_pcl_ros::BorderEstimator::publishCloud
virtual void publishCloud(ros::Publisher &pub, const pcl::PointIndices &inlier, const std_msgs::Header &header)
Definition: border_estimator_nodelet.cpp:103
PCLIndicesMsg
pcl::PointIndices PCLIndicesMsg
jsk_pcl_ros::BorderEstimator::pub_border_
ros::Publisher pub_border_
Definition: border_estimator.h:149
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::BorderEstimator, nodelet::Nodelet)
jsk_pcl_ros::BorderEstimator::pub_cloud_
ros::Publisher pub_cloud_
Definition: border_estimator.h:151
attention_pose_set.pub
pub
Definition: attention_pose_set.py:8
ros::Subscriber::shutdown
void shutdown()
jsk_pcl_ros::BorderEstimator::onInit
virtual void onInit()
Definition: border_estimator_nodelet.cpp:46
attention_pose_set.x
x
Definition: attention_pose_set.py:18
jsk_pcl_ros::BorderEstimator::model_type_
std::string model_type_
Definition: border_estimator.h:153
jsk_pcl_ros::BorderEstimator::computeBorder
virtual void computeBorder(const pcl::RangeImage &image, const std_msgs::Header &header)
Definition: border_estimator_nodelet.cpp:137
jsk_pcl_ros::BorderEstimator::max_angle_width_
double max_angle_width_
Definition: border_estimator.h:160
pcl::fromROSMsg
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
jsk_pcl_ros::BorderEstimator::angular_resolution_
double angular_resolution_
Definition: border_estimator.h:158
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
jsk_pcl_ros::BorderEstimator::pub_shadow_
ros::Publisher pub_shadow_
Definition: border_estimator.h:149
message_filters::Subscriber::unsubscribe
void unsubscribe()
cloud
cloud
jsk_pcl_ros::BorderEstimator::unsubscribe
virtual void unsubscribe()
Definition: border_estimator_nodelet.cpp:92
class_list_macros.h
jsk_pcl_ros::BorderEstimator::estimate
virtual void estimate(const sensor_msgs::PointCloud2::ConstPtr &msg, const sensor_msgs::CameraInfo::ConstPtr &caminfo)
Definition: border_estimator_nodelet.cpp:174
border_estimator.h
jsk_pcl_ros
Definition: add_color_from_image.h:51
jsk_pcl_ros::BorderEstimator::sync_
boost::shared_ptr< message_filters::Synchronizer< SyncPolicy > > sync_
Definition: border_estimator.h:147
jsk_pcl_ros::BorderEstimator::configCallback
virtual void configCallback(Config &config, uint32_t level)
Definition: border_estimator_nodelet.cpp:201
jsk_pcl_ros::BorderEstimator::noise_level_
double noise_level_
Definition: border_estimator.h:155
_1
boost::arg< 1 > _1
info
info
pcl_conversion_util.h
jsk_pcl_ros::BorderEstimator::Config
BorderEstimatorConfig Config
Definition: border_estimator.h:128
message_filters::Subscriber::subscribe
void subscribe()
jsk_pcl_ros::BorderEstimator::border_size_
int border_size_
Definition: border_estimator.h:157
nodelet::Nodelet
jsk_pcl_ros::BorderEstimator::min_range_
double min_range_
Definition: border_estimator.h:156
cv_bridge.h
dump_depth_error.f
f
Definition: dump_depth_error.py:39
jsk_recognition_utils::rangeImageToCvMat
void rangeImageToCvMat(const pcl::RangeImage &range_image, cv::Mat &mat)
cv_bridge::CvImage
jsk_pcl_ros::BorderEstimator::mutex_
boost::mutex mutex_
Definition: border_estimator.h:154
jsk_pcl_ros::BorderEstimator::max_angle_height_
double max_angle_height_
Definition: border_estimator.h:159
jsk_pcl_ros::BorderEstimator
Definition: border_estimator.h:91
pcl::toROSMsg
void toROSMsg(const pcl::PointCloud< T > &cloud, sensor_msgs::Image &msg)
sensor_msgs::image_encodings::BGR8
const std::string BGR8
attention_pose_set.y
y
Definition: attention_pose_set.py:19
config
config
jsk_pcl_ros::BorderEstimator::sub_camera_info_
message_filters::Subscriber< sensor_msgs::CameraInfo > sub_camera_info_
Definition: border_estimator.h:146
pose_with_covariance_sample.msg
msg
Definition: pose_with_covariance_sample.py:22
jsk_pcl_ros::BorderEstimator::~BorderEstimator
virtual ~BorderEstimator()
Definition: border_estimator_nodelet.cpp:67
jsk_pcl_ros::BorderEstimator::sub_point_
message_filters::Subscriber< sensor_msgs::PointCloud2 > sub_point_
Definition: border_estimator.h:145


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Tue Jan 7 2025 04:05:44