0
$\begingroup$

Rosanswers logo

Hello I am trying to convert laser scan data into images so that I can find "Lines". Following are the snippets from my code:

pcl::PointCloud<pcl::PointXYZRGB> cloudp;
sensor_msgs::Image image;

conversion

pcl::toROSMsg (cloudp, image); //convert the cloud


cloudxyz_.publish(cloudp);
image_pub_.publish (image); //publish our cloud image

When I run it, "Failed to find match for field 'rgb' " is the error I get. When I use rviz, all I see is an Image which is full of black color. My laser gives is 2D data (i.e, z in point cloud is 0) and I need a 2D image so that I can apply CV algorithms on the image.

Thank you.


Originally posted by San on ROS Answers with karma: 61 on 2016-02-20

Post score: 2


Original comments

Comment by srik11 on 2016-05-10:
Hello, were you able to get the image? I also am working on a similar issue. I am trying to find simple 2d shapes from laser scan data. I tried converting the point cloud to image. I also faced the same 'no rgb' issue. I converted the PointXYZ point cloud to PointXYZRGB type.

Comment by srik11 on 2016-05-10:
I found that the default rgb value was 0 which is black. I tried manually setting a rgb field.But i get an image with horizontal line with varying width. Wanted to know if you made any progress.

Comment by San on 2016-05-11:
Hi srik11, I posted the answer, have a look.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hello srik11 and all, If all you need is to convert laser scan msgs into an image and apply some cv algorithms, you don't even need PCL in between. This is how I did hallway detection from the laser data: (Note: This is not the only way. It works and does the job)

If you realized, the laser output is already in polar form i.e., (r, theta) [distance of object in a particular direction]. All you need to do is take an empty image (by which I mean an image with all white pixels) and using (r, theta) calculate (x, y) which is (r cos theta, r sin theta). Round of (x, y) and in the image, change the corresponding (x, y) pixel from white to black. Repeat this for all the (r, theta) pair from the laser scan. Please also note that you might want to shift the origin (laser origin is at the center and the image origin should always be on the top left corner - atleast for openCV image format). formulas for origin shift: X = x - h, Y = y - k.

You might want to scale the image down to a reasonable size for you to process it especially if your laser scanner range is high.

I hope this helps. Happy coding!


Originally posted by San with karma: 61 on 2016-05-11

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Aabed Solayman on 2020-04-16:
Hey San, so I'm trying your approach and I think this could be the answer to this question. There's a tiny problem. The data you get from the sensor (r) is float. and the pixels (x,y) should be integers right? I'm a beginner in OpenCV and trying to find an answer to this quesiton.

$\endgroup$

Your Answer

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