# Image array size is not consistent with the message type documentation

I am trying to interpret data from a message of the type sensor_msgs/Image. When I run rostopic echo ... for the topic, I get the following, along with the data array:

height: 720
width: 1280
encoding: 32FC1
is_bigendian: 0
step: 5120


The documentation says that the size of the array should be step times rows (i.e. height). This gives 720 times 5120 = 3686400 which is good because it says that 4 uint8 data elements in data array should be combined to get the 32 bit float value (see the encoding; 4 times 1280=5120 which is the step size).

To confirm the size of the data array, I edited my subscriber (added at the end) to read array elements corresponding to indices 3686400 to 4686400. I expected an error at the very beginning, but it threw a segmentation fault only after the index 3690487 . How can this be explained? What am I doing wrong? All the output values corresponding to these indices are zero. Right now this is how my subscriber looks:

#include <iostream>
#include "ros/ros.h"
//#include "std_msgs/String.h"
#include "sensor_msgs/Image.h"

using namespace std;

void depthCallback(const sensor_msgs::Image::ConstPtr& msg)
{
for(int i=3686400;i<4686400;i++)
{
//ROS_INFO("Height Info: [%d]", msg->height);
ROS_INFO("Depth Info: [%d]", msg->data[i]);
cout << "i VALUE: " << i << endl;
}
}

int main(int argc, char **argv)
{
//cout << "Hello world!" << endl;
ros::init(argc, argv, "zed_depth_subscriber_node");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/camera/depth/image_rect_color",1000, depthCallback);
ros::spin ();
return 0;
}

edit retag close merge delete

It is being published by the package zed-ros-wrapper using the launch file zed.launch.