0
$\begingroup$

Rosanswers logo

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 >}’ 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’ 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_8h.html#a3b07de2c80eff6c38c7ff881aa98eb22

How to solve this problem?

Thanks!


Originally posted by fafa on ROS Answers with karma: 1 on 2017-04-05

Post score: 0


Original comments

Comment by copyat300 on 2018-11-10:
I was about to devel into something Similar with the Walabot do you have your code on Github or anywhere?

$\endgroup$

1 Answer 1

1
$\begingroup$

Rosanswers logo

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;

Originally posted by agbj with karma: 83 on 2017-04-05

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

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