problem publishing OpenCV Image from FastRTPS to ROS2
Hello ROS2 community,
I'm trying to publish video camera images from opencv using fastRTPS standalone to ROS2 Node.
I've copied Image.idl from ROS2, built it like the HelloWorld example from fastRTPS. changed topicname to rt/topicname
and added the DS_
namespace as the answer in this post suggests link.
when I try to publish the image it shows on ROS2 network using ros2 topic echo
but after filling the data field of Image message with OpenCV MAT data. nothing shows.
I use the following function to convert OpenCV MAT to Image Message
void toImageMsg(sensor_msgs::msg::Image & ros_image, cv::Mat &image)
{
ros_image.height(image.rows);
ros_image.width(image.cols);
ros_image.encoding("bgr8");
ros_image.step(image.cols * image.elemSize());
size_t size = ros_image.step() * image.rows;
ros_image.data().resize(size);
memcpy(&ros_image.data()[0], image.data, size);
}
then mp_publisher->write(&st);
what I'm doing wrong?
the full project is here https://github.com/HemaZ/FastRTPS-ROS2
thank you in advance