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

Revision history [back]

click to hide/show revision 1
initial version

First of all try to use std::vector instead of raw pointers. It is best practice to do so. Your code is in c-style, not cpp style. Your problem can be solved doing what i have mentioned.

int** pointCloud; //double pointer for 2D Array with dimension sizeX and sizeY
std::vector<uint8_t> rasterImage; //array-variable
int sizeX; //amount of pixel along X-axis
int sizeY; //amount of pixel along Y-axis
int index; //represents value of reflected power

pointCloud = new int* [sizeX];
for (int x = 0; x < sizeX; x++)
{
    pointCloud[x] = new int [sizeY];
    for (int y = 0; y < sizeY; y++)
    {
        int index = (sizeX * y) + x;
        pointCloud[x][y] = rasterImage[index];
    }
}

for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { printf("%d ", pointCloud[x][y]); } printf("\n"); }

sensor_msgs::Image depth_image;

depth_image.height = sizeY;
depth_image.width = sizeX;
//depth_image.encoding = rgb8;
depth_image.is_bigendian = false;
depth_image.step = sizeX * sizeY;
depth_image.data = rasterImage;