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

How can I publish I420 image data as sensor_msgs/Image? (Image transport plugin)

asked 2020-02-11 14:18:54 -0600

JeyP4 gravatar image

From gstreamer v4l2src plugin, I get gstreamer buffer data(I420).

How can I publish it as sensor_msgs/Image? (Image transport plugin)

So I have a pointer to data. I know Height and width of final image. Anyways, I420 data arrangement mentioned in this post. (Just to indicate pixel arrangements, whole post in not important).

image_transport::Publisher pub = it.advertise("out_image_base_topic", 1);
mat = cv::Mat((height*3)/2, width, CV_8UC1, map.data);
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "i420", mat).toImageMsg();
pub.publish(msg);

Is it the correct way? Or first I have to convert image from I420 to BGR?

cvtColor(mat, mat, CV_YUV2BGR_I420, 3);
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-09-01 23:38:43 -0600

Hi Jey,

I had the same issue as you and decided to implement YUV420 conversion in cv_bridge so it will work by default with the rest of the ROS pipeline. Check out the following PRs (for ROS1):

https://github.com/ros/common_msgs/pu...

https://github.com/ros-perception/vis...

With the following branches all you have to do is set the encoding to yuv420, cv_bridge and the tools relying on it (i.e. rqt_image_view) should perform the conversion automatically.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-02-11 14:18:54 -0600

Seen: 541 times

Last updated: Sep 01 '20