Rosanswers logo

I cannot figure out what is the exact format of the sensor_msg Image() file. When I issue the command:

rostopic echo /camera/image_raw

I get a massive output consisting of thousands of numbers in an array. However, when I look up the documentation, there is supposed to be a heading, height, width, etc and the actual data. I have never been able to find the header or any other parameter from the output. I also cannot figure out just how large the file is. This makes it difficult to manipulate and transport the data. Can someone please help me out?

Originally posted by Tejas Rao on ROS Answers with karma: 3 on 2021-08-24

Post score: 0

Original comments

Comment by gvdhoorn on 2021-08-24:
The rostopic --help output may offer some guidance here:

  --nostr               exclude string fields
  --noarr               exclude arrays

if you add --noarr to your rostopic echo command, you'll be able to see the header and other non-array fields.

there is supposed to be a heading

probably a typo, but there is a header field. Not heading.

This makes it difficult to manipulate and transport the data.

A general usability suggestion: if you can accept the OpenCV dependency, try to consume sensor_msgs/Image messages using image_transport subscribers and convert messages to their OpenCV representation. That will make it much easier to work with them.

Working directly with the serialised form (in the form of sensor_msgs/Image) might not be the most efficient (from a usability perspective).


1 Answer 1


Rosanswers logo

Hello Tejas,

exact size of Image.

a. first way to get size. You can also get size from http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/Image.html by selecting this variable in your code.

uint32 height
uint32 width

Note: rostopic echo /camera/image_raw You are getting full sensor_msgs/Image data over here but each image has a huge matrix so you are not able to view the full message properly from your terminal.

b. second way to get size.

Just check if you are getting the camera_info topic. You can get this by typing rostopic list then try to view information of that you will get all details like height, width and other details which you required.

rostopic echo  <camers-info-topic>#/camera/color/camera_info

exact format

Have a look at this link you will get exact formate of an image message in ROS.


Originally posted by Ranjit Kathiriya with karma: 1622 on 2021-08-24

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Tejas Rao on 2021-08-25:
Thanks, this helped a lot!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.