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

Publishing 2D Array with sensor_msgs/Image

asked 2017-04-05 08:47:03 -0500

fafa gravatar image

updated 2017-04-10 06:31:11 -0500

I want to publish a 2D array, which is populated by int values. These values are delivered by a radar sensor and represent the reflected power of detected targets. So these values give information about the distance between the detected objects and the sensor.

This is an extract of my source code:

int* pointCloud //double pointer for 2D Array with dimension sizeX and sizeY int 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"); }

I want to create a image to visualize the detected objects. Now the problem is to fill the matrix data into the message and to publish rasterImage via sensor_msgs/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; --> ERROR MESSAGE

ERROR: no match for ‘operator=’ (operand types are ‘sensor_msgs::Image_<std::allocator<void> >::_data_type {aka std::vector<unsigned char,="" std::allocator<unsigned="" char=""> >}’ and ‘int*’)

Has anybody an advice to fix this problem?

==============================================

If I use std:vector<uint8_t> rasterImage, I get this error:

error: cannot convert ‘std::vector<unsigned char="">’ to ‘int’ for argument ‘1’ to ‘WALABOT_RESULT Walabot_GetRawImageSlice(int, int, int, double, double)’ res = Walabot_GetRawImageSlice(rasterImage, &sizeX, &sizeY, &sliceDepth, &power);

The function I'm using to get the values is this one:

http://api.walabot.com/_walabot_a_p_i...

How to solve this problem?

Thanks!

edit retag flag offensive close merge delete

Comments

I was about to devel into something Similar with the Walabot do you have your code on Github or anywhere?

copyat300 gravatar image copyat300  ( 2018-11-10 12:44:27 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-04-05 09:31:52 -0500

agbj gravatar image

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;
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-04-05 08:47:03 -0500

Seen: 1,004 times

Last updated: Apr 10 '17