callbacks.cpp
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <boost/bind.hpp>
4 #include <sensor_msgs/Image.h>
5 #include <visp/vpImage.h>
6 
7 #include <visp_tracker/Init.h>
8 
9 #include "names.hh"
10 #include "conversion.hh"
11 #include "callbacks.hh"
12 
13 # include <visp/vpMbEdgeTracker.h>
14 # include <visp/vpMbKltTracker.h>
15 
16 void imageCallback(vpImage<unsigned char>& image,
17  const sensor_msgs::Image::ConstPtr& msg,
18  const sensor_msgs::CameraInfoConstPtr& info)
19 {
20  try
21  {
22  rosImageToVisp(image, msg);
23  }
24  catch(std::exception& e)
25  {
26  ROS_ERROR_STREAM("dropping frame: " << e.what());
27  }
28 }
29 
30 void imageCallback(vpImage<unsigned char>& image,
31  std_msgs::Header& header,
32  sensor_msgs::CameraInfoConstPtr& info,
33  const sensor_msgs::Image::ConstPtr& msg,
34  const sensor_msgs::CameraInfoConstPtr& infoConst)
35 {
36  imageCallback(image, msg, info);
37  header = msg->header;
38  info = infoConst;
39 }
40 
42 bindImageCallback(vpImage<unsigned char>& image)
43 {
44  return boost::bind(imageCallback, boost::ref(image), _1, _2);
45 }
46 
48 bindImageCallback(vpImage<unsigned char>& image,
49  std_msgs::Header& header,
50  sensor_msgs::CameraInfoConstPtr& info)
51 {
52  return boost::bind
54  boost::ref(image), boost::ref(header), boost::ref(info), _1, _2);
55 }
56 
57 void reconfigureCallback(vpMbTracker* tracker,
58  vpImage<unsigned char>& I,
59  vpMe& moving_edge,
60  vpKltOpencv& kltTracker,
61  boost::recursive_mutex& mutex,
62  visp_tracker::ModelBasedSettingsConfig& config,
63  uint32_t level)
64 {
65  mutex.lock ();
66  try
67  {
68  ROS_INFO("Reconfigure Model Based Hybrid Tracker request received.");
69 
70  convertModelBasedSettingsConfigToVpMbTracker<visp_tracker::ModelBasedSettingsConfig>(config, tracker);
71 
72  convertModelBasedSettingsConfigToVpMe<visp_tracker::ModelBasedSettingsConfig>(config, moving_edge, tracker);
73 // moving_edge.print();
74 
75  convertModelBasedSettingsConfigToVpKltOpencv<visp_tracker::ModelBasedSettingsConfig>(config, kltTracker, tracker);
76 
77  vpHomogeneousMatrix cMo;
78  tracker->getPose(cMo);
79 
80 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
81  // Work arround for ViSP 2.9.0 to allow dynamic reconfigure to work
82  // when hybrid tracker is in use and moving edges settings are changed
83  vpMbKltTracker* tracker_klt = dynamic_cast<vpMbKltTracker*>(tracker);
84  if (tracker_klt != NULL)
85  tracker_klt->firstTrack = true;
86 #endif
87 
88  // Check if the image is ready to use
89  if (I.getHeight() != 0 && I.getWidth() != 0) {
90 #if VISP_VERSION_INT < VP_VERSION_INT(3,0,0)
91  // Could not use just initFromPose() for hybrid tracker
92  // init() function from edge tracker has to be fixed in the trunk first
93  // It might have to reset the meLines
94  tracker->setPose(I, cMo);
95 #endif
96  tracker->initFromPose(I, cMo);
97  }
98  }
99  catch (...)
100  {
101  mutex.unlock ();
102  throw;
103  }
104  mutex.unlock ();
105 }
106 
107 void reconfigureEdgeCallback(vpMbTracker* tracker,
108  vpImage<unsigned char>& I,
109  vpMe& moving_edge,
110  boost::recursive_mutex& mutex,
111  visp_tracker::ModelBasedSettingsEdgeConfig& config,
112  uint32_t level)
113 {
114 
115  mutex.lock ();
116  try
117  {
118  ROS_INFO("Reconfigure Model Based Edge Tracker request received.");
119 
120  convertModelBasedSettingsConfigToVpMbTracker<visp_tracker::ModelBasedSettingsEdgeConfig>(config, tracker);
121  convertModelBasedSettingsConfigToVpMe<visp_tracker::ModelBasedSettingsEdgeConfig>(config, moving_edge, tracker);
122  // moving_edge.print();
123 
124  // Check if the image is ready to use
125  if (I.getHeight() != 0 && I.getWidth() != 0) {
126  vpHomogeneousMatrix cMo;
127  tracker->getPose(cMo);
128  // Could not use initFromPose for edge tracker
129  // init() function has to be fixed in the trunk first
130  // It might have to reset the meLines
131  tracker->setPose(I, cMo);
132  }
133  }
134  catch (...)
135  {
136  mutex.unlock ();
137  throw;
138  }
139  mutex.unlock ();
140 }
141 
142 void reconfigureKltCallback(vpMbTracker* tracker,
143  vpImage<unsigned char>& I,
144  vpKltOpencv& kltTracker,
145  boost::recursive_mutex& mutex,
146  visp_tracker::ModelBasedSettingsKltConfig& config,
147  uint32_t level)
148 {
149  mutex.lock ();
150  try
151  {
152  ROS_INFO("Reconfigure Model Based KLT Tracker request received.");
153 
154  convertModelBasedSettingsConfigToVpMbTracker<visp_tracker::ModelBasedSettingsKltConfig>(config, tracker);
155  convertModelBasedSettingsConfigToVpKltOpencv<visp_tracker::ModelBasedSettingsKltConfig>(config, kltTracker, tracker);
156 
157  // Check if the image is ready to use
158  if (I.getHeight() != 0 && I.getWidth() != 0) {
159  vpHomogeneousMatrix cMo;
160  tracker->getPose(cMo);
161  tracker->initFromPose(I, cMo);
162  }
163  }
164  catch (...)
165  {
166  mutex.unlock ();
167  throw;
168  }
169  mutex.unlock ();
170 }
171 
173  vpMbTracker* tracker)
174 {
175  ros::ServiceClient clientViewer =
177  visp_tracker::Init srv;
178  convertVpMbTrackerToInitRequest(tracker, srv);
179  if (clientViewer.call(srv))
180  {
181  if (srv.response.initialization_succeed)
182  ROS_INFO("Tracker Viewer initialized with success.");
183  else
184  throw std::runtime_error("failed to initialize tracker viewer.");
185  }
186 }
187 
189  vpMbTracker* tracker,
190  vpImage<unsigned char>& I,
191  vpMe& moving_edge,
192  vpKltOpencv& kltTracker,
193  boost::recursive_mutex& mutex,
194  visp_tracker::ModelBasedSettingsConfig& config,
195  uint32_t level)
196 {
197  reconfigureCallback(tracker,I,moving_edge,kltTracker,mutex,config,level);
198  reInitViewerCommonParameters(nh,tracker);
199 }
200 
202  vpMbTracker* tracker,
203  vpImage<unsigned char>& I,
204  vpMe& moving_edge,
205  boost::recursive_mutex& mutex,
206  visp_tracker::ModelBasedSettingsEdgeConfig& config,
207  uint32_t level)
208 {
209  reconfigureEdgeCallback(tracker,I,moving_edge,mutex,config,level);
210  reInitViewerCommonParameters(nh,tracker);
211 }
212 
214  vpMbTracker* tracker,
215  vpImage<unsigned char>& I,
216  vpKltOpencv& kltTracker,
217  boost::recursive_mutex& mutex,
218  visp_tracker::ModelBasedSettingsKltConfig& config,
219  uint32_t level)
220 {
221  reconfigureKltCallback(tracker,I,kltTracker,mutex,config,level);
222  reInitViewerCommonParameters(nh,tracker);
223 }
void reconfigureKltCallbackAndInitViewer(ros::NodeHandle &nh, vpMbTracker *tracker, vpImage< unsigned char > &I, vpKltOpencv &kltTracker, boost::recursive_mutex &mutex, visp_tracker::ModelBasedSettingsKltConfig &config, uint32_t level)
Definition: callbacks.cpp:213
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void reconfigureCallback(vpMbTracker *tracker, vpImage< unsigned char > &I, vpMe &moving_edge, vpKltOpencv &kltTracker, boost::recursive_mutex &mutex, visp_tracker::ModelBasedSettingsConfig &config, uint32_t level)
Definition: callbacks.cpp:57
image_transport::CameraSubscriber::Callback bindImageCallback(vpImage< unsigned char > &image)
Definition: callbacks.cpp:42
bool call(MReq &req, MRes &res)
void convertVpMbTrackerToInitRequest(const vpMbTracker *tracker, visp_tracker::Init &srv)
Definition: conversion.cpp:208
void reInitViewerCommonParameters(ros::NodeHandle &nh, vpMbTracker *tracker)
Definition: callbacks.cpp:172
#define ROS_INFO(...)
void reconfigureEdgeCallbackAndInitViewer(ros::NodeHandle &nh, vpMbTracker *tracker, vpImage< unsigned char > &I, vpMe &moving_edge, boost::recursive_mutex &mutex, visp_tracker::ModelBasedSettingsEdgeConfig &config, uint32_t level)
Definition: callbacks.cpp:201
void reconfigureCallbackAndInitViewer(ros::NodeHandle &nh, vpMbTracker *tracker, vpImage< unsigned char > &I, vpMe &moving_edge, vpKltOpencv &kltTracker, boost::recursive_mutex &mutex, visp_tracker::ModelBasedSettingsConfig &config, uint32_t level)
Definition: callbacks.cpp:188
void imageCallback(vpImage< unsigned char > &image, const sensor_msgs::Image::ConstPtr &msg, const sensor_msgs::CameraInfoConstPtr &info)
Definition: callbacks.cpp:16
void reconfigureEdgeCallback(vpMbTracker *tracker, vpImage< unsigned char > &I, vpMe &moving_edge, boost::recursive_mutex &mutex, visp_tracker::ModelBasedSettingsEdgeConfig &config, uint32_t level)
Definition: callbacks.cpp:107
std::string reconfigure_service_viewer
void reconfigureKltCallback(vpMbTracker *tracker, vpImage< unsigned char > &I, vpKltOpencv &kltTracker, boost::recursive_mutex &mutex, visp_tracker::ModelBasedSettingsKltConfig &config, uint32_t level)
Definition: callbacks.cpp:142
boost::function< void(const sensor_msgs::ImageConstPtr &, const sensor_msgs::CameraInfoConstPtr &)> Callback
#define ROS_ERROR_STREAM(args)
void rosImageToVisp(vpImage< unsigned char > &dst, const sensor_msgs::Image::ConstPtr &src)
Convert a ROS image into a ViSP one.
Definition: conversion.cpp:27


visp_tracker
Author(s): Thomas Moulard
autogenerated on Wed Jul 3 2019 19:48:07