0
$\begingroup$

Rosanswers logo

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 ?


Originally posted by abhinav on ROS Answers with karma: 141 on 2011-09-26

Post score: 6

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dk with karma: 176 on 2011-09-26

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by dk on 2011-09-27:
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.

Comment by abhinav on 2011-09-26:
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

Comment by abhinav on 2011-09-26:
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.

Comment by 2ROS0 on 2018-02-07:
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 ?

$\endgroup$

Your Answer

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