undistort_depth.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include <ros/ros.h>
30 #include <nodelet/nodelet.h>
31 
32 #include <sensor_msgs/Image.h>
34 
38 
39 #include <cv_bridge/cv_bridge.h>
40 #include <opencv2/highgui/highgui.hpp>
41 
44 
45 namespace rtabmap_ros
46 {
47 
49 {
50 public:
52  {}
53 
54  virtual ~UndistortDepth()
55  {
56  }
57 
58 private:
59  virtual void onInit()
60  {
63 
64  std::string modelPath;
65  pnh.param("model", modelPath, modelPath);
66 
67  if(modelPath.empty())
68  {
69  NODELET_ERROR("undistort_depth: \"model\" parameter should be set!");
70  }
71 
72  model_.load(modelPath);
73  if(!model_.isValid())
74  {
75  NODELET_ERROR("Loaded distortion model from \"%s\" is not valid!", modelPath.c_str());
76  }
77  else
78  {
80  sub_ = it.subscribe("depth", 1, &UndistortDepth::callback, this);
81  pub_ = it.advertise(uFormat("%s_undistorted", nh.resolveName("depth").c_str()), 1);
82  }
83  }
84 
85  void callback(const sensor_msgs::ImageConstPtr& depth)
86  {
87  if(depth->encoding.compare(sensor_msgs::image_encodings::TYPE_16UC1)!=0 &&
88  depth->encoding.compare(sensor_msgs::image_encodings::TYPE_32FC1)!=0 &&
89  depth->encoding.compare(sensor_msgs::image_encodings::MONO16)!=0)
90  {
91  NODELET_ERROR("Input type depth=32FC1,16UC1,MONO16");
92  return;
93  }
94 
96  {
97  if(depth->width == model_.getWidth() && depth->width == model_.getWidth())
98  {
99  cv_bridge::CvImagePtr imageDepthPtr = cv_bridge::toCvCopy(depth);
100  model_.undistort(imageDepthPtr->image);
101  pub_.publish(imageDepthPtr->toImageMsg());
102  }
103  else
104  {
105  NODELET_ERROR("Input depth image size (%dx%d) and distortion model "
106  "size (%dx%d) don't match! Cannot undistort image.",
107  depth->width, depth->height,
109  }
110  }
111  }
112 
113 private:
117 };
118 
120 }
121 
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
std::string uFormat(const char *fmt,...)
#define NODELET_ERROR(...)
std::string resolveName(const std::string &name, bool remap=true) const
clams::DiscreteDepthDistortionModel model_
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
uint32_t getNumSubscribers() const
ros::NodeHandle & getPrivateNodeHandle() const
void publish(const sensor_msgs::Image &message) const
bool param(const std::string &param_name, T &param_val, const T &default_val) const
const std::string TYPE_32FC1
void callback(const sensor_msgs::ImageConstPtr &depth)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
const std::string TYPE_16UC1
const std::string MONO16
ros::NodeHandle & getNodeHandle() const
void load(const std::string &path)
image_transport::Publisher pub_
image_transport::Subscriber sub_
void undistort(cv::Mat &depth) const
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::CoreWrapper, nodelet::Nodelet)


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Fri Jun 7 2019 21:55:04