00001 #include <ros/ros.h>
00002 #include <sensor_msgs/Image.h>
00003 #include <message_transport/message_transport.h>
00004 #include <cv_bridge/CvBridge.h>
00005 #include <opencv/cv.h>
00006 #include <opencv/highgui.h>
00007
00008 class ImagePublisher {
00009 protected:
00010
00011 ros::NodeHandle n_;
00012 message_transport::MessageTransport<sensor_msgs::Image> it_;
00013 sensor_msgs::CvBridge bridge_;
00014 message_transport::Publisher image_pub_;
00015 IplImage *cv_image;
00016 sensor_msgs::Image image;
00017
00018
00019 public:
00020
00021 ImagePublisher(ros::NodeHandle &n) : n_(n),
00022 it_(n_,"imagem_transport","sensor_msgs::Image") {
00023 image_pub_ = it_.advertise("image_source",1);
00024
00025
00026
00027 cv_image = cvCreateImage(cvSize(1500,1000),8,3);
00028
00029 image = *(bridge_.cvToImgMsg(cv_image, "bgr8"));
00030 }
00031
00032 ~ImagePublisher()
00033 {
00034 }
00035
00036 int mainloop()
00037 {
00038
00039 ros::Rate loop_rate(30);
00040 while (ros::ok())
00041 {
00042 image.header.stamp = ros::Time::now();
00043 image_pub_.publish(image);
00044 ROS_DEBUG("Published image at %f",image.header.stamp.toSec());
00045 ros::spinOnce();
00046 loop_rate.sleep();
00047 }
00048
00049 return 0;
00050 }
00051
00052 };
00053
00054 int main(int argc, char** argv)
00055 {
00056 ros::init(argc, argv, "test_publisher");
00057 ros::NodeHandle n;
00058 ImagePublisher ic(n);
00059 ic.mainloop();
00060 return 0;
00061 }
00062