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


visp_tracker
Author(s): Thomas Moulard
autogenerated on Sat Mar 13 2021 03:20:06