Ask Your Question

Extracting width from PointCloud data

asked 2021-03-07 11:03:29 -0600

UndefinedDuck gravatar image

updated 2021-03-08 09:35:37 -0600

I wanna measure the width of a box from the laser data, I previously asked how to do that but nodoby helped me, so I'm trying to do it on my own. I don't know if I'm going in the right way but I converted my laser data into PointCloud2 data, then when I use the rostopic echo I can see all the data, in particular at the start it's written "width: 346". Is that the width of the box? If so, how can I publish that in another topic?


This is the box from Gazebo and in RViz I have the PointCloud, I wanna measure the length of that red line, so the width of the box:

link image:

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-03-08 09:06:26 -0600

tryan gravatar image

It's good that you're giving it a shot yourself; it gives people a better idea of your objective and shows that you're not just asking others to do it for you :).

As Akhil's answer indicates, the width parameter in the PointCloud2 message is metadata concerning the structure of the message data and does not indicate anything about what the data physically represents.

how can I publish that in another topic?

Publishing a topic is well covered by tutorials (C++, Python) and other questions on this site.

I wanna measure the width of a box from the laser data

For your goal, you'll have to implement a perception/computer vision algorithm, which is a very broad topic, and the details are highly dependent on your application. Such open ended questions are difficult to answer in a format like this, but I'll try. Here, we want the width of a box. One option would be to train a neural network to find the box and regress its boundary, but I would save that for more complex/general cases. If we can make some valid assumptions about the circumstances, then a more direct solution is possible. The more assumptions we make, the more constraints the problem has, and (usually) the simpler the algorithm. For example, assuming a 2-dimensional world is fairly common and eliminates a lot of complexity. We could also assume the box is sitting flat on the ground.

If we assume that the box is alone in the world, then every point in the point cloud belongs to the box, and locating it is no longer an issue. Otherwise, we may use a clustering algorithm to split the point cloud into objects and compare the objects' attributes to determine which is the box of interest. How best to find the box depends on what else we expect to exist in the world.

Once we have the set of points that represents the box, we have to measure its width. Again, assumptions can make this easy, but you have to determine which are valid for the application. If we assume that a rough estimate of the box size is good enough, we can just iterate through the box points to find the two farthest apart and call that its width. It may not be the exact length of a side--maybe it's actually the box's diagonal--but maybe that's close enough.

If we specifically want the length of a side we'll have to identify that side or figure out the box's orientation. If we assume we'll always approach the box perpendicularly to a face, then we can calculate y_max - y_min = width (the +y-axis being to our left). Otherwise, we may identify faces based on the surface normals. Then, we could group the points by surface normal and find the two most distant points within a group. This still carries the assumption that we've captured an entire side of the box in ... (more)

edit flag offensive delete link more


Thank you for the answer, that's exactly what I just did while waiting an answer. I converted my PointCloud data to PCL and now I have the x, y, z of every point. Then, I pushed these values into a list and got its fist and last element, which are the y_min and y_max of your answer. Then I used fabs(y_min - y_max) to calculate the width that I wanted! It's working good, but the problem is when I have 2 boxes, then the width of first is added to the width of the second one, how can I distinguish the width of the two? I guess I have to use the cluster you said, but how? There are some guides?

UndefinedDuck gravatar image UndefinedDuck  ( 2021-03-08 09:53:40 -0600 )edit

Yes, cluster extraction would help determine which points belong to which box. There are many algorithms, so you'll have to do some research to understand which is best for your application. I would recommend investigating Euclidean cluster extraction with PCL.

tryan gravatar image tryan  ( 2021-03-08 10:23:41 -0600 )edit

Thank you, I will try my best

UndefinedDuck gravatar image UndefinedDuck  ( 2021-03-08 10:40:36 -0600 )edit

answered 2021-03-07 16:08:52 -0600

If you refer the PointCloud2 data structure, you can see that the width (in case of an unstructured point cloud) gives the length of the point cloud. In other words, height * size gives you the size of the point cloud (number of points in the complete scan).

I wanna measure the width of a box from the laser data

What box? It would be helpful if you post a sample of your data and/or maybe images that depict what you are trying to convey. It is unclear what size you are trying to calculate

edit flag offensive delete link more


I edited the post for more clarification

UndefinedDuck gravatar image UndefinedDuck  ( 2021-03-08 03:27:58 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-03-07 11:03:29 -0600

Seen: 197 times

Last updated: Mar 08 '21