stereo_image_proc.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
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/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage 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 
35 #include <ros/ros.h>
36 #include <nodelet/loader.h>
38 
39 void loadMonocularNodelets(nodelet::Loader& manager, const std::string& side,
40  const XmlRpc::XmlRpcValue& rectify_params,
41  const nodelet::V_string& my_argv)
42 {
43  nodelet::M_string remappings;
44 
45  // Explicitly resolve global remappings (wg-ros-pkg #5055).
46  // Otherwise the internal remapping 'image_raw' -> 'left/image_raw' can hide a
47  // global remapping from the launch file or command line.
48  std::string image_raw_topic = ros::names::resolve(side + "/image_raw");
49  std::string image_mono_topic = ros::names::resolve(side + "/image_mono");
50  std::string image_color_topic = ros::names::resolve(side + "/image_color");
51  std::string image_rect_topic = ros::names::resolve(side + "/image_rect");
52  std::string image_rect_color_topic = ros::names::resolve(side + "/image_rect_color");
53  std::string camera_info_topic = ros::names::resolve(side + "/camera_info");
54 
55  // Debayer nodelet: image_raw -> image_mono, image_color
56  remappings["image_raw"] = image_raw_topic;
57  remappings["image_mono"] = image_mono_topic;
58  remappings["image_color"] = image_color_topic;
59  std::string debayer_name = ros::this_node::getName() + "_debayer_" + side;
60  manager.load(debayer_name, "image_proc/debayer", remappings, my_argv);
61 
62  // Rectify nodelet: image_mono -> image_rect
63  remappings.clear();
64  remappings["image_mono"] = image_mono_topic;
65  remappings["camera_info"] = camera_info_topic;
66  remappings["image_rect"] = image_rect_topic;
67  std::string rectify_mono_name = ros::this_node::getName() + "_rectify_mono_" + side;
68  if (rectify_params.valid())
69  ros::param::set(rectify_mono_name, rectify_params);
70  manager.load(rectify_mono_name, "image_proc/rectify", remappings, my_argv);
71 
72  // Rectify nodelet: image_color -> image_rect_color
73  remappings.clear();
74  remappings["image_mono"] = image_color_topic;
75  remappings["camera_info"] = camera_info_topic;
76  remappings["image_rect"] = image_rect_color_topic;
77  std::string rectify_color_name = ros::this_node::getName() + "_rectify_color_" + side;
78  if (rectify_params.valid())
79  ros::param::set(rectify_color_name, rectify_params);
80  manager.load(rectify_color_name, "image_proc/rectify", remappings, my_argv);
81 }
82 
83 int main(int argc, char **argv)
84 {
85  ros::init(argc, argv, "stereo_image_proc");
86 
87  // Check for common user errors
88  if (ros::names::remap("camera") != "camera")
89  {
90  ROS_WARN("Remapping 'camera' has no effect! Start stereo_image_proc in the "
91  "stereo namespace instead.\nExample command-line usage:\n"
92  "\t$ ROS_NAMESPACE=%s rosrun stereo_image_proc stereo_image_proc",
93  ros::names::remap("camera").c_str());
94  }
95  if (ros::this_node::getNamespace() == "/")
96  {
97  ROS_WARN("Started in the global namespace! This is probably wrong. Start "
98  "stereo_image_proc in the stereo namespace.\nExample command-line usage:\n"
99  "\t$ ROS_NAMESPACE=my_stereo rosrun stereo_image_proc stereo_image_proc");
100  }
101 
102  // Shared parameters to be propagated to nodelet private namespaces
103  ros::NodeHandle private_nh("~");
104  XmlRpc::XmlRpcValue shared_params;
105  int queue_size;
106  if (private_nh.getParam("queue_size", queue_size))
107  shared_params["queue_size"] = queue_size;
108 
109  nodelet::Loader manager(false); // Don't bring up the manager ROS API
110  nodelet::M_string remappings;
111  nodelet::V_string my_argv;
112 
113  // Load equivalents of image_proc for left and right cameras
114  loadMonocularNodelets(manager, "left", shared_params, my_argv);
115  loadMonocularNodelets(manager, "right", shared_params, my_argv);
116 
117  // Stereo nodelets also need to know the synchronization policy
118  bool approx_sync;
119  if (private_nh.getParam("approximate_sync", approx_sync))
120  shared_params["approximate_sync"] = XmlRpc::XmlRpcValue(approx_sync);
121 
122  // Disparity nodelet
123  // Inputs: left/image_rect, left/camera_info, right/image_rect, right/camera_info
124  // Outputs: disparity
125  // NOTE: Using node name for the disparity nodelet because it is the only one using
126  // dynamic_reconfigure so far, and this makes us backwards-compatible with cturtle.
127  std::string disparity_name = ros::this_node::getName();
128  manager.load(disparity_name, "stereo_image_proc/disparity", remappings, my_argv);
129 
130  // PointCloud2 nodelet
131  // Inputs: left/image_rect_color, left/camera_info, right/camera_info, disparity
132  // Outputs: points2
133  std::string point_cloud2_name = ros::this_node::getName() + "_point_cloud2";
134  if (shared_params.valid())
135  ros::param::set(point_cloud2_name, shared_params);
136  manager.load(point_cloud2_name, "stereo_image_proc/point_cloud2", remappings, my_argv);
137 
138  // Check for only the original camera topics
139  ros::V_string topics;
140  topics.push_back(ros::names::resolve("left/image_raw"));
141  topics.push_back(ros::names::resolve("left/camera_info"));
142  topics.push_back(ros::names::resolve("right/image_raw"));
143  topics.push_back(ros::names::resolve("right/camera_info"));
145  check_inputs.start(topics, 60.0);
146 
147  ros::spin();
148  return 0;
149 }
void loadMonocularNodelets(nodelet::Loader &manager, const std::string &side, const XmlRpc::XmlRpcValue &rectify_params, const nodelet::V_string &my_argv)
bool load(const std::string &name, const std::string &type, const M_string &remappings, const V_string &my_argv)
void start(const ros::V_string &topics, double duration)
bool valid() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
#define ROS_WARN(...)
ROSCPP_DECL void spin(Spinner &spinner)
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
std::vector< std::string > V_string
ROSCPP_DECL std::string remap(const std::string &name)
ROSCPP_DECL const std::string & getNamespace()
int main(int argc, char **argv)
bool getParam(const std::string &key, std::string &s) const
std::vector< std::string > V_string
std::map< std::string, std::string > M_string


stereo_image_proc
Author(s): Patrick Mihelich, Kurt Konolige, Jeremy Leibs
autogenerated on Thu Nov 7 2019 03:45:07