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

what is image step ?

asked 2011-09-26 01:14:32 -0600

updated 2014-01-28 17:10:26 -0600

ngrennan gravatar image

I wanted to use the toImageMsg() function to obtain ros image message using the image date from my usb cam. And as I was assigning header and encoding information, I came across this variable called "step" and then later the "size" is defined as: step_t size = image.step * image.rows;

then this "size" is passed to memcpy().

I do not know what exactly this step stands for and what is this size ? If I know both no of rows and columns in the image I can obtain the image size. Why do I need this step for then ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2011-09-26 04:10:12 -0600

dk gravatar image

updated 2011-09-26 05:31:29 -0600

According to the definition here, it is "Full row length in bytes".

There are multiple points that make this definition necessary:

  1. This format supports different image types. One pixel could consists of one byte (mono8), three byte (rgb8), three doubles, ... .
  2. For performance reasons the individual rows of your image might be aligned with special memory boundaries (e.g., word boundaries). In memory your (7*7) image might look like this: "IIIIIIIXIIIIIIIXIIIIIIIXIIIIIIIXIIIIIIIXIIIIIIIXIIIIIIIX" Here the Is are image bytes and the Xs are unused space bytes.

The image step gives you the distance in bytes between the first element of one row and the first element of the next row. You can see the openCV definition, that is similar (called widthStep there) here.

So, if the image coming from your cam is stored in memory without the mentioned unused space you can set image.step to image.cols * number_of_channels * sizeof(datatype_used) and everything should be fine. In the easiest case (mono8) image.step equals image.cols.

edit flag offensive delete link more

Comments

yes it worked fine for mono8 and I just discovered that I can directly pass the pointer to the memory space where my camera is storing images to ros as sensor_msgs using memcpy :) so no need to use the cv_bridge actually which some one else suggested me to convert the image data from camera to cv first and then use cv_bridge to convert to ros sensor message.
abhinav gravatar image abhinav  ( 2011-09-26 19:09:59 -0600 )edit
anyhow I still think the name step is not that clear as widthStep used by opencv and since not everyone using ros is familiar with opencv so this might lead to confusions. I would suggest, ros documentations should include links to the opencv documentation where needed or neccessary
abhinav gravatar image abhinav  ( 2011-09-26 19:13:20 -0600 )edit
There is a possibility to report a bug regarding the documentation within the vision_opencv stack here: http://www.ros.org/wiki/vision_opencv (look at the last line in the "Report a Bug" section). There is a high chance that the right people will not see your comment here.
dk gravatar image dk  ( 2011-09-27 01:16:35 -0600 )edit

If we were to set the step variable manually, do we need to account for any "space" like mentioned above? Or if I have an bgr8 image, can I just say step = width * 3 ?

2ROS0 gravatar image 2ROS0  ( 2018-02-07 14:12:39 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2011-09-26 01:14:32 -0600

Seen: 16,504 times

Last updated: Sep 26 '11