continuous_detector.cpp
Go to the documentation of this file.
1 
33 
35 
37 
38 namespace apriltag_ros
39 {
41 {
44 
45  tag_detector_ = std::shared_ptr<TagDetector>(new TagDetector(pnh));
46  draw_tag_detections_image_ = getAprilTagOption<bool>(pnh,
47  "publish_tag_detections_image", false);
48  it_ = std::shared_ptr<image_transport::ImageTransport>(
50 
51  std::string transport_hint;
52  pnh.param<std::string>("transport_hint", transport_hint, "raw");
53 
54  int queue_size;
55  pnh.param<int>("queue_size", queue_size, 1);
57  it_->subscribeCamera("image_rect", queue_size,
59  image_transport::TransportHints(transport_hint));
61  nh.advertise<AprilTagDetectionArray>("tag_detections", 1);
62  if (draw_tag_detections_image_)
63  {
64  tag_detections_image_publisher_ = it_->advertise("tag_detections_image", 1);
65  }
66 
68  pnh.advertiseService("refresh_tag_params",
70 }
71 
73 {
74  // Resetting the tag detector will cause a new param server lookup
75  // So if the parameters have changed (by someone/something),
76  // they will be updated dynamically
77  std::scoped_lock<std::mutex> lock(detection_mutex_);
79  tag_detector_.reset(new TagDetector(pnh));
80 }
81 
82 bool ContinuousDetector::refreshParamsCallback(std_srvs::Empty::Request& req,
83  std_srvs::Empty::Response& res)
84 {
86  return true;
87 }
88 
90  const sensor_msgs::ImageConstPtr& image_rect,
91  const sensor_msgs::CameraInfoConstPtr& camera_info)
92 {
93  std::scoped_lock<std::mutex> lock(detection_mutex_);
94  // Lazy updates:
95  // When there are no subscribers _and_ when tf is not published,
96  // skip detection.
99  !tag_detector_->get_publish_tf())
100  {
101  // ROS_INFO_STREAM("No subscribers and no tf publishing, skip processing.");
102  return;
103  }
104 
105  // Convert ROS's sensor_msgs::Image to cv_bridge::CvImagePtr in order to run
106  // AprilTag 2 on the iamge
107  try
108  {
109  cv_image_ = cv_bridge::toCvCopy(image_rect, image_rect->encoding);
110  }
111  catch (cv_bridge::Exception& e)
112  {
113  ROS_ERROR("cv_bridge exception: %s", e.what());
114  return;
115  }
116 
117  // Publish detected tags in the image by AprilTag 2
119  tag_detector_->detectTags(cv_image_,camera_info));
120 
121  // Publish the camera image overlaid by outlines of the detected tags and
122  // their payload values
124  {
125  tag_detector_->drawDetections(cv_image_);
127  }
128 }
129 
130 } // namespace apriltag_ros
uint32_t getNumSubscribers() const
ros::NodeHandle & getNodeHandle() const
ros::ServiceServer refresh_params_service_
ros::NodeHandle & getPrivateNodeHandle() const
image_transport::CameraSubscriber camera_image_subscriber_
std::shared_ptr< TagDetector > tag_detector_
void publish(const boost::shared_ptr< M > &message) const
bool refreshParamsCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
image_transport::Publisher tag_detections_image_publisher_
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
std::shared_ptr< image_transport::ImageTransport > it_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void publish(const sensor_msgs::Image &message) const
void imageCallback(const sensor_msgs::ImageConstPtr &image_rect, const sensor_msgs::CameraInfoConstPtr &camera_info)
uint32_t getNumSubscribers() const
#define ROS_ERROR(...)
PLUGINLIB_EXPORT_CLASS(apriltag_ros::ContinuousDetector, nodelet::Nodelet)


apriltag_ros
Author(s): Danylo Malyuta
autogenerated on Tue Mar 28 2023 02:10:49