ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

You subscribe to a topic receive images, modify them then publish them to a new topic in a single node, no problem at all.

If you look at the image publisher tutorial you can see how to publish an OpenCV image to a topic. You just need to add the advertise statement to setup the publisher at the start of main and add the following lines within the image callback function you've already got:

sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", <Your cv::Mat image>).toImageMsg();
pub.publish(msg);

If you want to save these images back to a bag file along with the input images, then you can record a new bag file as you are playing back the input bag file while running your node at the same time.

Hope this helps.

You subscribe to a topic receive images, modify them then publish them to a new topic in a single node, no problem at all.

If you look at the image publisher tutorial you can see how to publish an OpenCV image to a topic. You just need to add the advertise statement to setup the publisher at the start of main and add the following lines within the image callback function you've already got:

sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", <Your cv::Mat image>).toImageMsg();
pub.publish(msg);

If you want to save these images back to a bag file along with the input images, then you can record a new bag file as you are playing back the input bag file while running your node at the same time.

Hope this helps.

Update: If you need t use python, then you can avoid image_transport by opening the bag file directly using the rosbag API. There is a code example (a rather old one) in this answer which shows how to open a bag file and read images from it using python.