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

Revision history [back]

click to hide/show revision 1
initial version

cv::Mat by itself does not contain all of the information that sensor_msgs::Image does, namely the encoding (e.g. bgr8 vs rgb8) and the header (time stamp and tf frame). So you create a cv_bridge::CvImage object to convert:

#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>

cv_bridge::CvImage out_msg;
out_msg.header   = in_msg->header; // Same timestamp and tf frame as input image
out_msg.encoding = sensor_msgs::image_encodings::TYPE_32FC1; // Or whatever
out_msg.image    = sal_float_image; // Your cv::Mat

saliency_img_pub.publish(out_msg.toImageMsg());

It's a little verbose; in the future we could add constructors to CvImage to streamline this. Note that forgetting to set the header fields is a common bug when using the old CvBridge.