5 #include <boost/bind.hpp> 6 #include <boost/filesystem.hpp> 7 #include <boost/filesystem/fstream.hpp> 8 #include <boost/filesystem/path.hpp> 9 #include <boost/format.hpp> 10 #include <boost/optional.hpp> 16 #include <visp3/gui/vpDisplayX.h> 29 static void increment(
unsigned int* value)
39 visp_tracker::Init::Response& res)
41 boost::filesystem::ofstream modelStream;
45 throw std::runtime_error(
"failed to load the model from the callback");
55 res.initialization_succeed =
true;
61 visp_tracker::Init::Response& res)
67 res.initialization_succeed =
true;
108 std::string cameraPrefix;
111 while (cameraPrefix.empty ())
117 (
"the camera_prefix parameter does not exist.\n" 118 "This may mean that:\n" 119 "- the tracker is not launched,\n" 120 "- the tracker and viewer are not running in the same namespace." 123 else if (cameraPrefix.empty ())
126 (
"tracker is not yet initialized, waiting...\n" 127 "You may want to launch the client to initialize the tracker.");
153 boost::filesystem::ofstream modelStream;
156 unsigned int cpt = 0;
164 "The model_description parameter does not exist.\n" 165 "This may mean that:\n" 166 "- the tracker is not launched or not initialized,\n" 167 "- the tracker and viewer are not running in the same namespace." 179 throw std::runtime_error
180 (
"failed to load the model from the parameter server");
212 this, _1, _2, _3, _4, _5));
235 throw std::runtime_error(
"failed to retrieve image");
248 boost::format fmtWindowTitle (
"ViSP MBT tracker viewer - [ns: %s]");
253 fmtWindowTitle.str().c_str());
254 vpImagePoint point (10, 10);
255 vpImagePoint pointTime (22, 10);
256 vpImagePoint pointCameraTopic (34, 10);
259 boost::format fmt(
"tracking (x=%f y=%f z=%f)");
260 boost::format fmtTime(
"time = %f");
262 boost::format fmtCameraTopic(
"camera topic = %s");
266 vpDisplay::display(
image_);
284 fmt % (*cMo_)[0][3] % (*cMo_)[1][3] % (*cMo_)[2][3];
285 vpDisplay::displayCharString
286 (
image_, point, fmt.str().c_str(), vpColor::red);
287 fmtTime %
info_->header.stamp.toSec();
288 vpDisplay::displayCharString
289 (
image_, pointTime, fmtTime.str().c_str(), vpColor::red);
290 vpDisplay::displayCharString
291 (
image_, pointCameraTopic, fmtCameraTopic.str().c_str(),
295 vpDisplay::displayCharString
296 (
image_, point,
"tracking failed", vpColor::red);
336 bool loadParam =
false;
338 if(trackerName_.empty())
341 trackerName_ =
"tracker_mbt";
344 ROS_WARN_STREAM(
"No tracker has been found with the default name value \"" 345 << trackerName_ <<
"/angle_appear\".\n" 346 <<
"Tracker name parameter (tracker_name) should be provided for this node (tracker_viewer).\n" 347 <<
"Polygon visibility might not work well in the viewer window.");
349 else loadParam =
true;
351 else loadParam =
true;
353 else loadParam =
true;
363 tracker_.setAngleAppear(vpMath::rad(value));
368 ROS_WARN_STREAM(
"No tracker has been found with the provided parameter " 369 <<
"(tracker_name=\"" << trackerName_ <<
"\")\n" 370 <<
"Polygon visibility might not work well in the viewer window");
378 tracker_.setAngleDisappear(vpMath::rad(value));
394 boost::format fmt(
"failed to load the model %1%");
396 throw std::runtime_error(fmt.str());
403 (
const sensor_msgs::ImageConstPtr& image,
404 const sensor_msgs::CameraInfoConstPtr& info,
405 const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& trackingResult,
406 const visp_tracker::MovingEdgeSites::ConstPtr& sites,
407 const visp_tracker::KltPoints::ConstPtr& klt)
414 catch(std::exception& e)
425 cMo_ = vpHomogeneousMatrix();
434 for (
unsigned i = 0; i <
sites_->moving_edge_sites.size(); ++i)
436 double x =
sites_->moving_edge_sites[i].x;
437 double y =
sites_->moving_edge_sites[i].y;
438 int suppress =
sites_->moving_edge_sites[i].suppress;
439 vpColor color = vpColor::black;
443 case vpMeSite::NO_SUPPRESSION:
444 color = vpColor::green;
446 case vpMeSite::CONSTRAST:
447 color = vpColor::blue;
449 case vpMeSite::THRESHOLD:
450 color = vpColor::purple;
452 case vpMeSite::M_ESTIMATOR:
453 color = vpColor::red;
456 color = vpColor::yellow;
459 vpDisplay::displayCross(
image_, vpImagePoint(x, y), 3, color, 1);
471 for (
unsigned i = 0; i <
klt_->klt_points_positions.size(); ++i)
473 double ii =
klt_->klt_points_positions[i].i;
474 double jj =
klt_->klt_points_positions[i].j;
475 int id =
klt_->klt_points_positions[i].id;
476 vpColor color = vpColor::red;
478 vpDisplay::displayCross(
image_, vpImagePoint(ii, jj), 15, color, 1);
480 pos.set_i( vpMath::round( ii + 7 ) );
481 pos.set_j( vpMath::round( jj + 7 ) );
483 sprintf(ide,
"%d",
id);
484 vpDisplay::displayCharString(
image_, pos, ide, vpColor::red);
495 (
"[visp_tracker] Low number of synchronized tuples received.\n" 498 "Tracking result: %d\n" 499 "Moving edge sites: %d\n" 501 "Synchronized tuples: %d\n" 503 "\t* The network is too slow.");
image_transport::ImageTransport imageTransport_
Image transport used to receive images.
ros::NodeHandle & nodeHandle_
#define ROS_DEBUG_STREAM_THROTTLE(rate, args)
void transformToVpHomogeneousMatrix(vpHomogeneousMatrix &dst, const geometry_msgs::Transform &src)
void displayMovingEdgeSites()
Display moving edge sites.
void waitForImage()
Hang until the first image is received.
message_filters::Subscriber< geometry_msgs::PoseWithCovarianceStamped > trackingResultSubscriber_
Subscriber to tracking result topic.
std::string rectifiedImageTopic_
Full topic name for rectified image.
void start(const ros::V_string &topics, double duration)
std::string moving_edge_sites_topic
boost::function< bool(visp_tracker::Init::Request &, visp_tracker::Init::Response &res)> initCallback_t
std::string getName(void *handle)
boost::function< bool(visp_tracker::Init::Request &, visp_tracker::Init::Response &res)> reconfigureCallback_t
ros::ServiceServer reconfigureService_
Service called when user is reconfiguring tracker node.
ROSCPP_DECL const std::string & getName()
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
TFSIMD_FORCE_INLINE const tfScalar & y() const
vpMbGenericTracker tracker_
ViSP edge tracker.
message_filters::Subscriber< visp_tracker::KltPoints > kltPointsSubscriber_
Subscriber to KLT point topics.
visp_tracker::KltPoints::ConstPtr klt_
Shared pointer to latest received KLT point positions.
image_proc::AdvertisementChecker checkInputs_
Helper used to check that subscribed topics exist.
std::string trackerName_
Name of the tracker used in this viewer node.
TrackerViewer(ros::NodeHandle &nh, ros::NodeHandle &privateNh, volatile bool &exiting, unsigned queueSize=5u)
Constructor.
ros::NodeHandle & nodeHandlePrivate_
std::vector< std::string > V_string
void displayKltPoints()
Display KLT points that are tracked.
boost::filesystem::path modelPath_
Model path.
ROSCPP_DECL const std::string & getNamespace()
ROSCPP_DECL bool get(const std::string &key, std::string &s)
image_t image_
ViSP image.
bool initCallback(visp_tracker::Init::Request &req, visp_tracker::Init::Response &res)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::string model_description_param
bool reconfigureCallback(visp_tracker::Init::Request &req, visp_tracker::Init::Response &res)
void callback(const sensor_msgs::ImageConstPtr &imageConst, const sensor_msgs::CameraInfoConstPtr &infoConst, const geometry_msgs::PoseWithCovarianceStamped::ConstPtr &trackingResult, const visp_tracker::MovingEdgeSites::ConstPtr &sitesConst, const visp_tracker::KltPoints::ConstPtr &kltConst)
Callback used to received synchronized data.
sensor_msgs::CameraInfoConstPtr info_
Shared pointer to latest received camera information.
WallTimer createWallTimer(WallDuration period, void(T::*callback)(const WallTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
std::string reconfigure_service_viewer
#define ROS_WARN_STREAM(args)
unsigned countTrackingResult_
image_transport::SubscriberFilter imageSubscriber_
ros::ServiceServer initService_
Service called when user ends tracker_client node.
void subscribe(ImageTransport &it, const std::string &base_topic, uint32_t queue_size, const TransportHints &transport_hints=TransportHints())
#define ROS_WARN_STREAM_THROTTLE(rate, args)
void checkInputs()
Make sure the topics we subscribe already exist.
message_filters::Synchronizer< syncPolicy_t > synchronizer_
Synchronizer with approximate time policy.
vpCameraParameters cameraParameters_
ViSP camera parameters.
message_filters::Subscriber< visp_tracker::MovingEdgeSites > movingEdgeSitesSubscriber_
Subscriber to moving edge sites topics.
void initializeTracker()
Initialize the tracker.
unsigned queueSize_
Queue size for all subscribers.
#define ROS_INFO_STREAM(args)
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
std::string cameraInfoTopic_
Full topic name for camera information.
boost::optional< vpHomogeneousMatrix > cMo_
Last tracked object position, set to none if tracking failed.
bool getParam(const std::string &key, std::string &s) const
unsigned countMovingEdgeSites_
void initializeVpCameraFromCameraInfo(vpCameraParameters &cam, sensor_msgs::CameraInfoConstPtr info)
std::string object_position_covariance_topic
void spin()
Display camera image, tracked object position and moving edge sites.
#define ROS_INFO_THROTTLE(rate,...)
std::string init_service_viewer
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoSubscriber_
Subscriber to camera information topic.
std::string object_position_topic
void convertInitRequestToVpMbTracker(const visp_tracker::Init::Request &req, vpMbGenericTracker &tracker)
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)
std::string klt_points_topic
ROSCPP_DECL void spinOnce()
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)
unsigned countCameraInfo_
visp_tracker::MovingEdgeSites::ConstPtr sites_
Shared pointer to latest received moving edge sites.
bool makeModelFile(boost::filesystem::ofstream &modelStream, std::string &fullModelPath)
void increment(int *value)
Connection registerCallback(const C &callback)
void loadCommonParameters()
Initialize the common parameters (visibility angles, etc)
void rosImageToVisp(vpImage< unsigned char > &dst, const sensor_msgs::Image::ConstPtr &src)
Convert a ROS image into a ViSP one.