Ask Your Question
0

How to create a .bag from processed images using cv_bridge?

asked 2018-06-04 09:39:43 -0600

latida gravatar image

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).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-04 11:26:02 -0600

updated 2018-06-05 06:45:16 -0600

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.

edit flag offensive delete link more

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?

latida gravatar imagelatida ( 2018-06-05 02:42:33 -0600 )edit

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

latida gravatar imagelatida ( 2018-06-05 07:59:19 -0600 )edit

I'm sorry to bother you, but I'm new to ROS so I may misunderstood some procedures. I appreciate your help:)

latida gravatar imagelatida ( 2018-06-05 08:55:55 -0600 )edit

See my updated answer, I've linked to an example that should help you.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-06-05 12:39:42 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-06-04 09:39:43 -0600

Seen: 176 times

Last updated: Jun 05 '18