mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
image_publisher.h
1 #ifndef _IMAGE_TRANSPORTER_
2 #define _IMAGE_TRANSPORTER_
3 
4 #include <opencv2/core/core.hpp>
5 #include <cv_bridge/cv_bridge.h>
6 #include <image_transport/image_transport.h>
7 #include <ros/ros.h>
8 #include <mutex>
9 #include <memory>
10 
11 namespace mrs_lib {
12 
14  ImagePubliserData(const image_transport::Publisher& publisher, const std::string& topic_name, const ros::Time& last_hit)
15  :
16  publisher(publisher),
17  topic_name(topic_name),
18  last_hit(last_hit) {};
19  image_transport::Publisher publisher;
20  std::string topic_name;
21  std::mutex pub_mutex;
22  ros::Time last_hit;
23  };
24 
26  public:
27  ImagePublisher(ros::NodeHandlePtr nh_);
28  bool publish(std::string topic_name, double throttle_period, cv::Mat& image, bool bgr_order = false);
29 
30  private:
31  std::string getEncoding(cv::Mat& input, bool bgr_order);
32  bool throttle(int index, double throttle_period);
33 
34  ros::NodeHandlePtr nh;
35  std::vector<std::unique_ptr<ImagePubliserData>> imagePublishers;
36  std::unique_ptr<image_transport::ImageTransport> transport;
37  cv_bridge::CvImage outputImage;
38  sensor_msgs::ImagePtr msg;
39  bool throttle_pass;
40  std::mutex main_pub_mutex;
41 
42 
43  };
44 
45 }
46 #endif //_IMAGE_TRANSPORTER_
mrs_lib::ImagePubliserData
Definition: image_publisher.h:13
mrs_lib
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
mrs_lib::ImagePublisher
Definition: image_publisher.h:25