How to create a .bag from processed images using cv_bridge?
Hi, I have to process images from a .bag file (in ROS kinetic) which contains sensor_msgs/Image type of messages. I'm following this tutorial where processed images are shown in CV window. How can I show and store processed images using ROS? How can I make a new topic (for example named "processed") and publish processed images to it? I'm confused whether I have to write a new node or add this reverse procedure to an existing one (like this tutorial).
Asked by latida on 2018-06-04 09:39:43 UTC
Answers
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.
Asked by PeteBlackerThe3rd on 2018-06-04 11:26:02 UTC
Comments
Hi, thanks a lot, but my code is in Python and it says in this tutorial that image_transport doesn't support Python. What should be my next step then?
Asked by latida on 2018-06-05 02:42:33 UTC
Thanks,but I specifically have to process the stream of msgs (images) published from a topic from a sensor.That's why I'm using that tutorial I've mentioned earlier in my question. I'm not sure how to add a new topic (ex. named "Processed"), publish processed image msgs to it and save into bag after
Asked by latida on 2018-06-05 07:59:19 UTC
I'm sorry to bother you, but I'm new to ROS so I may misunderstood some procedures. I appreciate your help:)
Asked by latida on 2018-06-05 08:55:55 UTC
See my updated answer, I've linked to an example that should help you.
Asked by PeteBlackerThe3rd on 2018-06-05 12:39:42 UTC
Comments