keypoints_publisher_nodelet.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Yuki Furuta and JSK Lab
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/o2r other materials provided
16  * with the distribution.
17  * * Neither the name of the JSK Lab nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
37 
41 
42 #include <pcl/range_image/range_image_planar.h>
43 #include <pcl/keypoints/narf_keypoint.h>
44 #include <pcl/features/range_image_border_extractor.h>
45 
46 namespace jsk_pcl_ros
47 {
49  {
50  ConnectionBasedNodelet::onInit();
51 
52  input_.reset(new pcl::PointCloud<pcl::PointXYZ>);
53  keypoints_pub_ = advertise<sensor_msgs::PointCloud2>(*pnh_, "nerf_keypoints", 10);
54 
56  }
57 
59  {
60  sub_input_ = pnh_->subscribe("input", 1, &KeypointsPublisher::inputCallback, this);
61  }
62 
64  {
66  }
67 
68  void KeypointsPublisher::inputCallback(const sensor_msgs::PointCloud2::ConstPtr& input)
69  {
70  pcl::fromROSMsg(*input, *input_);
71  input_header_ = input->header;
73  }
74 
75  void KeypointsPublisher::extractKeypoints(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
76  {
77  pcl::RangeImagePlanar rip;
78  pcl::RangeImageBorderExtractor ribe;
79  rip.createFromPointCloudWithFixedSize(*cloud, cloud->width, cloud->height,
80  319.5, 239.5, 525.0, 525.0, static_cast<Eigen::Affine3f>(Eigen::Translation3f(0.0, 0.0, 0.0)));
81  rip.setUnseenToMaxRange();
82  ROS_INFO_STREAM("Built range image " << rip.width << "x" << rip.height);
83 
84  pcl::NarfKeypoint narf;
85  narf.setRangeImageBorderExtractor(&ribe);
86  narf.setRangeImage(&rip);
87  narf.getParameters().support_size = 0.1;
88  narf.getParameters().use_recursive_scale_reduction = true;
89  narf.getParameters().calculate_sparse_interest_image = true;
90 
91  pcl::PointCloud<int> indices;
92  narf.compute(indices);
93 
94  pcl::PointCloud<pcl::PointXYZ> result;
95  for (int i = 0; i < indices.size(); ++i) {
96  result.push_back(cloud->at(indices[i]));
97  }
98  sensor_msgs::PointCloud2 resMsg;
99  pcl::toROSMsg(result, resMsg);
100  resMsg.header = input_header_;
101  keypoints_pub_.publish(resMsg);
102  }
103 
104 }
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::KeypointsPublisher, nodelet::Nodelet)
void publish(const boost::shared_ptr< M > &message) const
virtual void extractKeypoints(pcl::PointCloud< pcl::PointXYZ >::Ptr cloud)
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
virtual void inputCallback(const sensor_msgs::PointCloud2::ConstPtr &input)
result
boost::shared_ptr< ros::NodeHandle > pnh_
pcl::PointCloud< pcl::PointXYZ >::Ptr input_
void toROSMsg(const pcl::PointCloud< T > &pcl_cloud, sensor_msgs::PointCloud2 &cloud)
#define ROS_INFO_STREAM(args)


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:47