6 #include <std_msgs/String.h>
7 #include <ros/console.h>
8 #include <opencv2/opencv.hpp>
10 #include <boost/timer/timer.hpp>
13 #include <std_msgs/Int64.h>
15 #include <image_transport/image_transport.h>
16 #include <image_geometry/pinhole_camera_model.h>
17 #include <tf/transform_listener.h>
18 #include <sensor_msgs/image_encodings.h>
19 #include <sensor_msgs/distortion_models.h>
20 #include <sys/ioctl.h>
21 #include <linux/videodev2.h>
25 #include <vision_module/Tools/LineSegment.hpp>
26 #include <vision_module/Tools/General.hpp>
27 #include <cv_bridge/cv_bridge.h>
28 #include <sensor_msgs/image_encodings.h>
29 #include <config_server/parameter.h>
30 #include <std_srvs/Empty.h>
31 #include <boost/format.hpp>
43 ros::NodeHandle nodeHandle;
44 cv_bridge::CvImage msg;
45 image_transport::ImageTransport it;
46 image_transport::Publisher img_pub;
48 const int currentNumber;
56 inline MatPublisher(
string name =
"",
bool _enable =
true) :
57 it(nodeHandle), currentNumber(number++), enable(_enable),hasListener(
false)
62 if (name.length() < 1)
64 sprintf(cName,
"/vision/debug/img%d", currentNumber);
68 sprintf(cName,
"%s", name.c_str());
70 img_pub = it.advertise(cName, 1);
71 msg.header.frame_id =
"/picture";
74 inline void publish(Mat img, imgColorType t, ros::Time now =
77 hasListener=(img_pub.getNumSubscribers() > 0);
78 if (!enable || !hasListener)
84 msg.encoding = sensor_msgs::image_encodings::MONO8;
88 msg.encoding = sensor_msgs::image_encodings::BGR8;
89 cvtColor(img, res, CV_HSV2BGR);
93 msg.encoding = sensor_msgs::image_encodings::BGR8;
97 msg.header.stamp = now;
99 img_pub.publish(msg.toImageMsg());
102 inline bool thereAreListeners(
bool loadNow=
true)
106 hasListener=(img_pub.getNumSubscribers() > 0);
A class for publish mat objects.
Definition: MatPublisher.hpp:40