conversion.hh
Go to the documentation of this file.
1 #ifndef VISP_TRACKER_CONVERSION_HH
2 # define VISP_TRACKER_CONVERSION_HH
3 # include <boost/optional.hpp>
4 
5 # include <ros/ros.h>
6 
7 # include <geometry_msgs/Transform.h>
8 # include <sensor_msgs/Image.h>
9 # include <sensor_msgs/CameraInfo.h>
10 # include <tf/transform_datatypes.h>
11 
12 # include <visp_tracker/Init.h>
13 
14 #include <visp/vpConfig.h>
15 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
16 # define protected public
17 #endif
18 # include <visp/vpMbEdgeTracker.h>
19 # include <visp/vpMbKltTracker.h>
20 # include <visp/vpMbTracker.h>
21 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
22 # undef protected
23 #endif
24 
25 # include <visp/vpHomogeneousMatrix.h>
26 # include <visp/vpCameraParameters.h>
27 # include <visp/vpMe.h>
28 # include <visp/vpKltOpencv.h>
29 
40 void rosImageToVisp(vpImage<unsigned char>& dst,
41  const sensor_msgs::Image::ConstPtr& src);
42 
53 void vispImageToRos(sensor_msgs::Image& dst,
54  const vpImage<unsigned char>& src);
55 
56 std::string convertVpMbTrackerToRosMessage(const vpMbTracker* tracker);
57 
58 std::string convertVpMeToRosMessage(const vpMbTracker* tracker, const vpMe& moving_edge);
59 
60 std::string convertVpKltOpencvToRosMessage(const vpMbTracker* tracker, const vpKltOpencv& klt);
61 
62 void vpHomogeneousMatrixToTransform(geometry_msgs::Transform& dst,
63  const vpHomogeneousMatrix& src);
64 
65 void transformToVpHomogeneousMatrix(vpHomogeneousMatrix& dst,
66  const geometry_msgs::Transform& src);
67 
68 void transformToVpHomogeneousMatrix(vpHomogeneousMatrix& dst,
69  const tf::Transform& src);
70 
71 void transformToVpHomogeneousMatrix(vpHomogeneousMatrix& dst,
72  const geometry_msgs::Pose& src);
73 
74 void convertVpMbTrackerToInitRequest(const vpMbTracker* tracker,
75  visp_tracker::Init& srv);
76 
77 void convertInitRequestToVpMbTracker(const visp_tracker::Init::Request& req,
78  vpMbTracker* tracker);
79 
80 void convertVpMeToInitRequest(const vpMe& moving_edge,
81  const vpMbTracker* tracker,
82  visp_tracker::Init& srv);
83 
84 void convertInitRequestToVpMe(const visp_tracker::Init::Request& req,
85  vpMbTracker* tracker,
86  vpMe& moving_edge);
87 
88 void convertVpKltOpencvToInitRequest(const vpKltOpencv& klt,
89  const vpMbTracker* tracker,
90  visp_tracker::Init& srv);
91 
92 void convertInitRequestToVpKltOpencv(const visp_tracker::Init::Request& req,
93  vpMbTracker* tracker,
94  vpKltOpencv& klt);
95 
96 void initializeVpCameraFromCameraInfo(vpCameraParameters& cam,
97  sensor_msgs::CameraInfoConstPtr info);
98 
99 // Dynamic reconfigure template functions
100 template<class ConfigType>
101 void convertModelBasedSettingsConfigToVpMbTracker(const ConfigType& config,
102  vpMbTracker* tracker)
103 {
104 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
105  tracker->setAngleAppear(vpMath::rad(config.angle_appear));
106  tracker->setAngleDisappear(vpMath::rad(config.angle_disappear));
107 #else
108  vpMbEdgeTracker* tracker_edge = dynamic_cast<vpMbEdgeTracker*>(tracker);
109  if (tracker_edge != NULL) { // Also valid when hybrid
110  ROS_INFO("Set param angle from edge");
111  tracker_edge->setAngleAppear(vpMath::rad(config.angle_appear));
112  tracker_edge->setAngleDisappear(vpMath::rad(config.angle_disappear));
113  }
114  else {
115  vpMbKltTracker* tracker_klt = dynamic_cast<vpMbKltTracker*>(tracker);
116  if (tracker_klt != NULL) {
117  ROS_INFO("Set param angle from klt");
118  tracker_klt->setAngleAppear(vpMath::rad(config.angle_appear));
119  tracker_klt->setAngleDisappear(vpMath::rad(config.angle_disappear));
120  }
121  }
122 #endif
123 }
124 
125 template<class ConfigType>
126 void convertVpMbTrackerToModelBasedSettingsConfig(const vpMbTracker* tracker,
127  ConfigType& config)
128 {
129 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
130  config.angle_appear = vpMath::deg(tracker->getAngleAppear());
131  config.angle_disappear = vpMath::deg(tracker->getAngleDisappear());
132 #else
133  const vpMbEdgeTracker* tracker_edge = dynamic_cast<const vpMbEdgeTracker*>(tracker);
134  if (tracker_edge != NULL) {
135  ROS_INFO("Modif config param angle from edge");
136  config.angle_appear = vpMath::deg(tracker_edge->getAngleAppear());
137  config.angle_disappear = vpMath::deg(tracker_edge->getAngleDisappear());
138  }
139  else {
140  const vpMbKltTracker* tracker_klt = dynamic_cast<const vpMbKltTracker*>(tracker);
141  if (tracker_klt != NULL) {
142  ROS_INFO("Modif config param angle from klt");
143  config.angle_appear = vpMath::deg(tracker_klt->getAngleAppear());
144  config.angle_disappear = vpMath::deg(tracker_klt->getAngleDisappear());
145  }
146  }
147 #endif
148 }
149 
150 template<class ConfigType>
151 void convertModelBasedSettingsConfigToVpMe(const ConfigType& config,
152  vpMe& moving_edge,
153  vpMbTracker* tracker)
154 {
155  vpMbEdgeTracker* t = dynamic_cast<vpMbEdgeTracker*>(tracker);
156 
157 
158 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
159  t->setGoodMovingEdgesRatioThreshold(config.first_threshold);
160  moving_edge.setThreshold( config.threshold );
161  moving_edge.setMaskSize( config.mask_size );
162  moving_edge.setRange( config.range );
163  moving_edge.setMu1( config.mu1 );
164  moving_edge.setMu2( config.mu2 );
165  moving_edge.setSampleStep( config.sample_step );
166  moving_edge.setStrip( config.strip );
167 #else
168  t->setFirstThreshold(config.first_threshold);
169  moving_edge.threshold = config.threshold;
170  moving_edge.mask_size = config.mask_size;
171  moving_edge.range = config.range;
172  moving_edge.mu1 = config.mu1;
173  moving_edge.mu2 = config.mu2;
174  moving_edge.sample_step = config.sample_step;
175  moving_edge.strip = config.strip;
176 #endif
177 
178  //FIXME: not sure if this is needed.
179  moving_edge.initMask();
180  //Reset the tracker and the node state.
181  t->setMovingEdge(moving_edge);
182 }
183 
184 template<class ConfigType>
185 void convertVpMeToModelBasedSettingsConfig(const vpMe& moving_edge,
186  const vpMbTracker* tracker,
187  ConfigType& config)
188 {
189  const vpMbEdgeTracker* t = dynamic_cast<const vpMbEdgeTracker*>(tracker);
190 
191 
192 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
193  config.first_threshold = t->getGoodMovingEdgesRatioThreshold();
194  config.threshold = moving_edge.getThreshold();
195  config.mask_size = moving_edge.getMaskSize();
196  config.range = moving_edge.getRange();
197  config.mu1 = moving_edge.getMu1();
198  config.mu2 = moving_edge.getMu2();
199  config.sample_step = moving_edge.getSampleStep();
200  config.strip = moving_edge.getStrip();
201 #else
202  config.first_threshold = t->getFirstThreshold();
203  config.threshold = moving_edge.threshold;
204  config.mask_size = moving_edge.mask_size;
205  config.range = moving_edge.range;
206  config.mu1 = moving_edge.mu1;
207  config.mu2 = moving_edge.mu2;
208  config.sample_step = moving_edge.sample_step;
209  config.strip = moving_edge.strip;
210 #endif
211 }
212 
213 template<class ConfigType>
214 void convertModelBasedSettingsConfigToVpKltOpencv(const ConfigType& config,
215  vpKltOpencv& klt,
216  vpMbTracker* tracker)
217 {
218  vpMbKltTracker* t = dynamic_cast<vpMbKltTracker*>(tracker);
219 
220  klt.setMaxFeatures(config.max_features);
221  klt.setWindowSize(config.window_size);
222  klt.setQuality(config.quality);
223  klt.setMinDistance(config.min_distance);
224  klt.setHarrisFreeParameter(config.harris);
225  klt.setBlockSize(config.size_block);
226  klt.setPyramidLevels(config.pyramid_lvl);
227  t->setMaskBorder((unsigned)config.mask_border);
228 
229  t->setKltOpencv(klt);
230 }
231 
232 template<class ConfigType>
234  const vpMbTracker* tracker,
235  ConfigType& config)
236 {
237  const vpMbKltTracker* t = dynamic_cast<const vpMbKltTracker*>(tracker);
238 
239  config.max_features = klt.getMaxFeatures();
240  config.window_size = klt.getWindowSize();
241  config.quality = klt.getQuality();
242  config.min_distance = klt.getMinDistance();
243  config.harris = klt.getHarrisFreeParameter();
244  config.size_block = klt.getBlockSize();
245  config.pyramid_lvl = klt.getPyramidLevels();
246  config.mask_border = t->getMaskBorder();
247 }
248 
249 #endif
void convertInitRequestToVpMe(const visp_tracker::Init::Request &req, vpMbTracker *tracker, vpMe &moving_edge)
Definition: conversion.cpp:282
void vpHomogeneousMatrixToTransform(geometry_msgs::Transform &dst, const vpHomogeneousMatrix &src)
Definition: conversion.cpp:151
std::string convertVpMbTrackerToRosMessage(const vpMbTracker *tracker)
Definition: conversion.cpp:87
void convertVpMeToModelBasedSettingsConfig(const vpMe &moving_edge, const vpMbTracker *tracker, ConfigType &config)
Definition: conversion.hh:185
void convertVpMbTrackerToInitRequest(const vpMbTracker *tracker, visp_tracker::Init &srv)
Definition: conversion.cpp:208
void vispImageToRos(sensor_msgs::Image &dst, const vpImage< unsigned char > &src)
Convert a ViSP image into a ROS one.
Definition: conversion.cpp:73
std::string convertVpMeToRosMessage(const vpMbTracker *tracker, const vpMe &moving_edge)
Definition: conversion.cpp:113
void convertVpKltOpencvToInitRequest(const vpKltOpencv &klt, const vpMbTracker *tracker, visp_tracker::Init &srv)
Definition: conversion.cpp:314
std::string convertVpKltOpencvToRosMessage(const vpMbTracker *tracker, const vpKltOpencv &klt)
Definition: conversion.cpp:134
void initializeVpCameraFromCameraInfo(vpCameraParameters &cam, sensor_msgs::CameraInfoConstPtr info)
Definition: conversion.cpp:348
void convertVpMbTrackerToModelBasedSettingsConfig(const vpMbTracker *tracker, ConfigType &config)
Definition: conversion.hh:126
void transformToVpHomogeneousMatrix(vpHomogeneousMatrix &dst, const geometry_msgs::Transform &src)
Definition: conversion.cpp:167
void convertModelBasedSettingsConfigToVpMbTracker(const ConfigType &config, vpMbTracker *tracker)
Definition: conversion.hh:101
void convertVpMeToInitRequest(const vpMe &moving_edge, const vpMbTracker *tracker, visp_tracker::Init &srv)
Definition: conversion.cpp:254
#define ROS_INFO(...)
void rosImageToVisp(vpImage< unsigned char > &dst, const sensor_msgs::Image::ConstPtr &src)
Convert a ROS image into a ViSP one.
Definition: conversion.cpp:27
void convertVpKltOpencvToModelBasedSettingsConfig(const vpKltOpencv &klt, const vpMbTracker *tracker, ConfigType &config)
Definition: conversion.hh:233
void convertModelBasedSettingsConfigToVpKltOpencv(const ConfigType &config, vpKltOpencv &klt, vpMbTracker *tracker)
Definition: conversion.hh:214
void convertModelBasedSettingsConfigToVpMe(const ConfigType &config, vpMe &moving_edge, vpMbTracker *tracker)
Definition: conversion.hh:151
void convertInitRequestToVpMbTracker(const visp_tracker::Init::Request &req, vpMbTracker *tracker)
Definition: conversion.cpp:232
void convertInitRequestToVpKltOpencv(const visp_tracker::Init::Request &req, vpMbTracker *tracker, vpKltOpencv &klt)
Definition: conversion.cpp:330


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