Publishing compressed images that can be recorded with rosbag

asked 2022-01-27 10:22:08 -0500

kolja gravatar image

updated 2022-01-27 18:23:31 -0500

Hi, i have a cv::Mat image that i want to publish and record with rosbag.

cv::Mat mat1(qImage.height(),qImage.width(),CV_8UC4, (uchar*)qImage.bits(),qImage.bytesPerLine());
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgra8", mat1).toImageMsg();
pub.publish(msg);

This is Working the way it should. I can subscribe to the topic and view the image. The problem is that i only publish pointers and i cant record pointers with rosbag and replay them later if i am right. I could just publish the raw data with an array the size 1600x1200x4 with 8 Bit per entry. There has to be a smarter solution but i couldnt find it yet. What would be the best way to publish images that can be stored by rosbags in a efficient way?

I am using noetic if that helps.

Thanks for any advice

edit retag flag offensive close merge delete

Comments

Quick note: in ROS 1, you cannot "publish pointers", and toImageMsg() returns an actual message object.

If you can "subscribe to the topic and view the image", then RosBag can record it.

gvdhoorn gravatar image gvdhoorn  ( 2022-01-28 05:12:46 -0500 )edit