Go to the documentation of this file.00001 #ifndef VISP_TRACKER_CONVERSION_HH
00002 # define VISP_TRACKER_CONVERSION_HH
00003 # include <boost/optional.hpp>
00004
00005 # include <ros/ros.h>
00006
00007 # include <geometry_msgs/Transform.h>
00008 # include <sensor_msgs/Image.h>
00009 # include <sensor_msgs/CameraInfo.h>
00010 # include <tf/transform_datatypes.h>
00011
00012 # include <visp_tracker/Init.h>
00013
00014 #include <visp/vpConfig.h>
00015 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
00016 # define protected public
00017 #endif
00018 # include <visp/vpMbEdgeTracker.h>
00019 # include <visp/vpMbKltTracker.h>
00020 # include <visp/vpMbTracker.h>
00021 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0)
00022 # undef protected
00023 #endif
00024
00025 # include <visp/vpHomogeneousMatrix.h>
00026 # include <visp/vpCameraParameters.h>
00027 # include <visp/vpMe.h>
00028 # include <visp/vpKltOpencv.h>
00029
00040 void rosImageToVisp(vpImage<unsigned char>& dst,
00041 const sensor_msgs::Image::ConstPtr& src);
00042
00053 void vispImageToRos(sensor_msgs::Image& dst,
00054 const vpImage<unsigned char>& src);
00055
00056 std::string convertVpMbTrackerToRosMessage(const vpMbTracker* tracker);
00057
00058 std::string convertVpMeToRosMessage(const vpMbTracker* tracker, const vpMe& moving_edge);
00059
00060 std::string convertVpKltOpencvToRosMessage(const vpMbTracker* tracker, const vpKltOpencv& klt);
00061
00062 void vpHomogeneousMatrixToTransform(geometry_msgs::Transform& dst,
00063 const vpHomogeneousMatrix& src);
00064
00065 void transformToVpHomogeneousMatrix(vpHomogeneousMatrix& dst,
00066 const geometry_msgs::Transform& src);
00067
00068 void transformToVpHomogeneousMatrix(vpHomogeneousMatrix& dst,
00069 const tf::Transform& src);
00070
00071 void transformToVpHomogeneousMatrix(vpHomogeneousMatrix& dst,
00072 const geometry_msgs::Pose& src);
00073
00074 void convertVpMbTrackerToInitRequest(const vpMbTracker* tracker,
00075 visp_tracker::Init& srv);
00076
00077 void convertInitRequestToVpMbTracker(const visp_tracker::Init::Request& req,
00078 vpMbTracker* tracker);
00079
00080 void convertVpMeToInitRequest(const vpMe& moving_edge,
00081 const vpMbTracker* tracker,
00082 visp_tracker::Init& srv);
00083
00084 void convertInitRequestToVpMe(const visp_tracker::Init::Request& req,
00085 vpMbTracker* tracker,
00086 vpMe& moving_edge);
00087
00088 void convertVpKltOpencvToInitRequest(const vpKltOpencv& klt,
00089 const vpMbTracker* tracker,
00090 visp_tracker::Init& srv);
00091
00092 void convertInitRequestToVpKltOpencv(const visp_tracker::Init::Request& req,
00093 vpMbTracker* tracker,
00094 vpKltOpencv& klt);
00095
00096 void initializeVpCameraFromCameraInfo(vpCameraParameters& cam,
00097 sensor_msgs::CameraInfoConstPtr info);
00098
00099
00100 template<class ConfigType>
00101 void convertModelBasedSettingsConfigToVpMbTracker(const ConfigType& config,
00102 vpMbTracker* tracker)
00103 {
00104 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
00105 tracker->setAngleAppear(vpMath::rad(config.angle_appear));
00106 tracker->setAngleDisappear(vpMath::rad(config.angle_disappear));
00107 #else
00108 vpMbEdgeTracker* tracker_edge = dynamic_cast<vpMbEdgeTracker*>(tracker);
00109 if (tracker_edge != NULL) {
00110 ROS_INFO("Set param angle from edge");
00111 tracker_edge->setAngleAppear(vpMath::rad(config.angle_appear));
00112 tracker_edge->setAngleDisappear(vpMath::rad(config.angle_disappear));
00113 }
00114 else {
00115 vpMbKltTracker* tracker_klt = dynamic_cast<vpMbKltTracker*>(tracker);
00116 if (tracker_klt != NULL) {
00117 ROS_INFO("Set param angle from klt");
00118 tracker_klt->setAngleAppear(vpMath::rad(config.angle_appear));
00119 tracker_klt->setAngleDisappear(vpMath::rad(config.angle_disappear));
00120 }
00121 }
00122 #endif
00123 }
00124
00125 template<class ConfigType>
00126 void convertVpMbTrackerToModelBasedSettingsConfig(const vpMbTracker* tracker,
00127 ConfigType& config)
00128 {
00129 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
00130 config.angle_appear = vpMath::deg(tracker->getAngleAppear());
00131 config.angle_disappear = vpMath::deg(tracker->getAngleDisappear());
00132 #else
00133 const vpMbEdgeTracker* tracker_edge = dynamic_cast<const vpMbEdgeTracker*>(tracker);
00134 if (tracker_edge != NULL) {
00135 ROS_INFO("Modif config param angle from edge");
00136 config.angle_appear = vpMath::deg(tracker_edge->getAngleAppear());
00137 config.angle_disappear = vpMath::deg(tracker_edge->getAngleDisappear());
00138 }
00139 else {
00140 const vpMbKltTracker* tracker_klt = dynamic_cast<const vpMbKltTracker*>(tracker);
00141 if (tracker_klt != NULL) {
00142 ROS_INFO("Modif config param angle from klt");
00143 config.angle_appear = vpMath::deg(tracker_klt->getAngleAppear());
00144 config.angle_disappear = vpMath::deg(tracker_klt->getAngleDisappear());
00145 }
00146 }
00147 #endif
00148 }
00149
00150 template<class ConfigType>
00151 void convertModelBasedSettingsConfigToVpMe(const ConfigType& config,
00152 vpMe& moving_edge,
00153 vpMbTracker* tracker)
00154 {
00155 vpMbEdgeTracker* t = dynamic_cast<vpMbEdgeTracker*>(tracker);
00156
00157 moving_edge.mask_size = config.mask_size;
00158 moving_edge.range = config.range;
00159 moving_edge.threshold = config.threshold;
00160 moving_edge.mu1 = config.mu1;
00161 moving_edge.mu2 = config.mu2;
00162 moving_edge.sample_step = config.sample_step;
00163 moving_edge.strip = config.strip;
00164
00165 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
00166 t->setGoodMovingEdgesRatioThreshold(config.first_threshold);
00167
00168 #else
00169 t->setFirstThreshold(config.first_threshold);
00170 #endif
00171
00172
00173 moving_edge.initMask();
00174
00175 t->setMovingEdge(moving_edge);
00176 }
00177
00178 template<class ConfigType>
00179 void convertVpMeToModelBasedSettingsConfig(const vpMe& moving_edge,
00180 const vpMbTracker* tracker,
00181 ConfigType& config)
00182 {
00183 const vpMbEdgeTracker* t = dynamic_cast<const vpMbEdgeTracker*>(tracker);
00184
00185 config.mask_size = moving_edge.mask_size;
00186 config.range = moving_edge.range;
00187 config.threshold = moving_edge.threshold;
00188 config.mu1 = moving_edge.mu1;
00189 config.mu2 = moving_edge.mu2;
00190 config.sample_step = moving_edge.sample_step;
00191 config.strip = moving_edge.strip;
00192
00193 #if VISP_VERSION_INT >= VP_VERSION_INT(2,10,0)
00194 config.first_threshold = t->getGoodMovingEdgesRatioThreshold();
00195 #else
00196 config.first_threshold = t->getFirstThreshold();
00197 #endif
00198 }
00199
00200 template<class ConfigType>
00201 void convertModelBasedSettingsConfigToVpKltOpencv(const ConfigType& config,
00202 vpKltOpencv& klt,
00203 vpMbTracker* tracker)
00204 {
00205 vpMbKltTracker* t = dynamic_cast<vpMbKltTracker*>(tracker);
00206
00207 klt.setMaxFeatures(config.max_features);
00208 klt.setWindowSize(config.window_size);
00209 klt.setQuality(config.quality);
00210 klt.setMinDistance(config.min_distance);
00211 klt.setHarrisFreeParameter(config.harris);
00212 klt.setBlockSize(config.size_block);
00213 klt.setPyramidLevels(config.pyramid_lvl);
00214 t->setMaskBorder((unsigned)config.mask_border);
00215
00216 t->setKltOpencv(klt);
00217 }
00218
00219 template<class ConfigType>
00220 void convertVpKltOpencvToModelBasedSettingsConfig(const vpKltOpencv& klt,
00221 const vpMbTracker* tracker,
00222 ConfigType& config)
00223 {
00224 const vpMbKltTracker* t = dynamic_cast<const vpMbKltTracker*>(tracker);
00225
00226 config.max_features = klt.getMaxFeatures();
00227 config.window_size = klt.getWindowSize();
00228 config.quality = klt.getQuality();
00229 config.min_distance = klt.getMinDistance();
00230 config.harris = klt.getHarrisFreeParameter();
00231 config.size_block = klt.getBlockSize();
00232 config.pyramid_lvl = klt.getPyramidLevels();
00233 config.mask_border = t->getMaskBorder();
00234 }
00235
00236 #endif //! VISP_TRACKER_CONVERSION_HH