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 <visp/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");
56 res.initialization_succeed =
true;
62 visp_tracker::Init::Response& res)
68 res.initialization_succeed =
true;
109 std::string cameraPrefix;
112 while (cameraPrefix.empty ())
118 (
"the camera_prefix parameter does not exist.\n" 119 "This may mean that:\n" 120 "- the tracker is not launched,\n" 121 "- the tracker and viewer are not running in the same namespace." 124 else if (cameraPrefix.empty ())
127 (
"tracker is not yet initialized, waiting...\n" 128 "You may want to launch the client to initialize the tracker.");
154 boost::filesystem::ofstream modelStream;
157 unsigned int cpt = 0;
165 "The model_description parameter does not exist.\n" 166 "This may mean that:\n" 167 "- the tracker is not launched or not initialized,\n" 168 "- the tracker and viewer are not running in the same namespace." 180 throw std::runtime_error
181 (
"failed to load the model from the parameter server");
213 this, _1, _2, _3, _4, _5));
236 throw std::runtime_error(
"failed to retrieve image");
249 boost::format fmtWindowTitle (
"ViSP MBT tracker viewer - [ns: %s]");
254 fmtWindowTitle.str().c_str());
255 vpImagePoint point (10, 10);
256 vpImagePoint pointTime (22, 10);
257 vpImagePoint pointCameraTopic (34, 10);
260 boost::format fmt(
"tracking (x=%f y=%f z=%f)");
261 boost::format fmtTime(
"time = %f");
263 boost::format fmtCameraTopic(
"camera topic = %s");
267 vpDisplay::display(
image_);
285 fmt % (*cMo_)[0][3] % (*cMo_)[1][3] % (*cMo_)[2][3];
286 vpDisplay::displayCharString
287 (
image_, point, fmt.str().c_str(), vpColor::red);
288 fmtTime %
info_->header.stamp.toSec();
289 vpDisplay::displayCharString
290 (
image_, pointTime, fmtTime.str().c_str(), vpColor::red);
291 vpDisplay::displayCharString
292 (
image_, pointCameraTopic, fmtCameraTopic.str().c_str(),
296 vpDisplay::displayCharString
297 (
image_, point,
"tracking failed", vpColor::red);
337 bool loadParam =
false;
339 if(trackerName_.empty())
342 trackerName_ =
"tracker_mbt";
345 ROS_WARN_STREAM(
"No tracker has been found with the default name value \"" 346 << trackerName_ <<
"/angle_appear\".\n" 347 <<
"Tracker name parameter (tracker_name) should be provided for this node (tracker_viewer).\n" 348 <<
"Polygon visibility might not work well in the viewer window.");
350 else loadParam =
true;
352 else loadParam =
true;
354 else loadParam =
true;
364 tracker_.setAngleAppear(vpMath::rad(value));
369 ROS_WARN_STREAM(
"No tracker has been found with the provided parameter " 370 <<
"(tracker_name=\"" << trackerName_ <<
"\")\n" 371 <<
"Polygon visibility might not work well in the viewer window");
379 tracker_.setAngleDisappear(vpMath::rad(value));
395 boost::format fmt(
"failed to load the model %1%");
397 throw std::runtime_error(fmt.str());
404 (
const sensor_msgs::ImageConstPtr& image,
405 const sensor_msgs::CameraInfoConstPtr& info,
406 const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& trackingResult,
407 const visp_tracker::MovingEdgeSites::ConstPtr& sites,
408 const visp_tracker::KltPoints::ConstPtr& klt)
415 catch(std::exception& e)
426 cMo_ = vpHomogeneousMatrix();
435 for (
unsigned i = 0; i <
sites_->moving_edge_sites.size(); ++i)
437 double x =
sites_->moving_edge_sites[i].x;
438 double y =
sites_->moving_edge_sites[i].y;
439 int suppress =
sites_->moving_edge_sites[i].suppress;
440 vpColor color = vpColor::black;
444 case vpMeSite::NO_SUPPRESSION:
445 color = vpColor::green;
447 case vpMeSite::CONSTRAST:
448 color = vpColor::blue;
450 case vpMeSite::THRESHOLD:
451 color = vpColor::purple;
453 case vpMeSite::M_ESTIMATOR:
454 color = vpColor::red;
457 color = vpColor::yellow;
460 vpDisplay::displayCross(
image_, vpImagePoint(x, y), 3, color, 1);
472 for (
unsigned i = 0; i <
klt_->klt_points_positions.size(); ++i)
474 double ii =
klt_->klt_points_positions[i].i;
475 double jj =
klt_->klt_points_positions[i].j;
476 int id =
klt_->klt_points_positions[i].id;
477 vpColor color = vpColor::red;
479 vpDisplay::displayCross(
image_, vpImagePoint(ii, jj), 15, color, 1);
481 pos.set_i( vpMath::round( ii + 7 ) );
482 pos.set_j( vpMath::round( jj + 7 ) );
484 sprintf(ide,
"%d",
id);
485 vpDisplay::displayCharString(
image_, pos, ide, vpColor::red);
496 (
"[visp_tracker] Low number of synchronized tuples received.\n" 499 "Tracking result: %d\n" 500 "Moving edge sites: %d\n" 502 "Synchronized tuples: %d\n" 504 "\t* The network is too slow.");
image_transport::ImageTransport imageTransport_
Image transport used to receive images.
ros::NodeHandle & nodeHandle_
void transformToVpHomogeneousMatrix(vpHomogeneousMatrix &dst, const geometry_msgs::Transform &src)
void displayMovingEdgeSites()
Display moving edge sites.
#define ROS_WARN_STREAM_THROTTLE(period, args)
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
void convertInitRequestToVpMbTracker(const visp_tracker::Init::Request &req, vpMbTracker *tracker)
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
#define ROS_DEBUG_STREAM_THROTTLE(period, args)
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_
vpMbEdgeTracker tracker_
ViSP edge tracker.
std::vector< std::string > V_string
void displayKltPoints()
Display KLT points that are tracked.
boost::filesystem::path modelPath_
Model path.
#define ROS_INFO_THROTTLE(period,...)
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())
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.
std::string init_service_viewer
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoSubscriber_
Subscriber to camera information topic.
std::string object_position_topic
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.