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

How to make an unordered pointcloud ordered with a given color image?

asked 2023-05-17 18:55:41 -0500

iHany gravatar image

I have a pcd and png files (namely, a.pcd and a.png). Also, I have a ROS package (namely, MyROS), which receives ROS Image and PointCloud2 (XYZ), supposed to be ordered corresponding to the image.

I used pcd_to_pointcloud to publish a pointcloud. When I used the command like

rosrun pcl_ros pcd_to_pointcloud a.pcd [ interval ] , I found that the resulting ros topic is a PointCloud2 with fields of X, Y, and Z (no RGB). Also, the pointcloud is flattened, i.e., its height = 1.

I published ROS Image and PointCloud2 corresponding to the files and republish a pointcloud by changing its property with the published ROS Image, for example,

pcd_msg.height = image_msg.height
pcd_msg.width = image_msg.width
pcd_msg.row_step = image_msg.row_step
pcd_msg.point_step = image_msg.point_step

But it seems not to work with my package. More precisely, I used read_points but no points are read, which surely worked with an ordered pc streamed from my RealSense.

I may misunderstand the properties of PointCloud2. Can anybody help me?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-19 04:58:35 -0500

bluegiraffe-sc gravatar image

Hi!

For what we can see from the code snippet you have posted, you are not adding the RGB data to the point cloud at all. Moreover, the Image message does not have a point_step field. I think that this is the reason why you cannot read the republished Pointcloud2. Actually, I am surprised that that line is not throwing an error.

As for the height and width attributes, I think that, for your camera, they have the same values both for the Pointcloud2 and Image message (but check it out with, e.g., rostopic), so these two lines are probably not doing anything.

To add the RGB information to the point cloud, you have to add a sensor_msgs/PointField to the fields of the point cloud message, and store the RGB values there (in an ordered way).

I hope that this can help you a little!

edit flag offensive delete link more

Comments

1

Thank you so much! After struggling for a bit more with your advice, I found that this works well:

pcd_msg.height = image_msg.height
pcd_msg.width = image_msg.width
pcd_msg.row_step = int(len(pcd_msg.data) / pcd_msg.height)

Thanks a lot!

iHany gravatar image iHany  ( 2023-05-21 03:16:18 -0500 )edit
1

You are welcome, glad you solved!

Can you confirm that the reason why you were not able to read your own re-published point clouds was indeed the wrong row_step field value?

Also, did you manage to add the RGB values to the point cloud? If so, you could share your implementation to help whoever will land on this thread in the future!

bluegiraffe-sc gravatar image bluegiraffe-sc  ( 2023-05-22 10:25:35 -0500 )edit

Yes, one has to re-assign the value of row_step appropriately, and does not change the point_step. I did not add the RGB values to the original XYZ point cloud as my algorithm did not require that. But I guess that it is possible by assigning the fields of RGB in the point cloud (not sure tho!). I'd like to share my implementation as well but I cannot as it is not published yet. Hope my comments help for the future readers :>

iHany gravatar image iHany  ( 2023-05-22 19:08:52 -0500 )edit

Clear!

Sorry, but I have just realized I misunderstood your initial question. I thought your actual goal was ordering the point cloud and adding the RGB values. Glad that my not-very-aware advice helped you anyway!

bluegiraffe-sc gravatar image bluegiraffe-sc  ( 2023-05-23 01:56:40 -0500 )edit

Weirdly, after a while, I was looking for what you said haha My answer is: https://answers.ros.org/question/4156...

iHany gravatar image iHany  ( 2023-05-23 02:44:28 -0500 )edit

Question Tools

Stats

Asked: 2023-05-17 18:55:41 -0500

Seen: 165 times

Last updated: May 19 '23