Publishing compressed images that can be recorded with rosbag
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
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.