Detect steps in a pointcloud with RANSAC

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Detect steps in a pointcloud with RANSAC

Senf
Hello,

I am using the model: SACMODEL_PERPENDICULAR_PLANE to detect planes in the pointcloud. The goal is to detect single steps (of a staircase) but at the moment the model gives me planes with points from the whole pointcloud. So, what I want is that it returns me planes with high points density. How can I add the condition to only take points in the neighboors for the RANSAC model?

Would greatly appreciate any help!

Best
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Sneaky Polar Bear
tbh I have not yet used that particular function, but...
I am confident that you could use region growing segmentation as a prep step to get only each face of the stairs separated.
Setting that up to make sure that it splits the surfaces at each of the 90 degree turns, you could cycle through your now vector of segmented clouds and do a plane fit on each one.  (this would give you only local point clouds that would then be fed into Ransac separately, sry if there is a built in way that i am ignorant to)

I am pretty sure this would also speed up your Ransac as you would be looking at smaller point clouds (and planes would converge faster) rather than the whole thing (but this is a guess).

Depending on the shape of your stairs (if they have a rounded lip or not), you may be able to even be fancy and segment each step (including front and top face).  Basically you would want to set up the segmentation to look for that sharp angle at the bottom of each step and overlook the rounded lip.  This could be useful if you are looking at a larger scene and need to positive id something as a stair or not as it will represent two strong planes with a clean angle between them.
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Senf
Thank you very much for your suggestion Polar Bear. Have one question: what is exactly the output of the regional growing segmentation?
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Sneaky Polar Bear
It gives you a vector of point indices:
std::vector <pcl::PointIndices> clusters; //object for holding results of segmentation
reg.extract (clusters);  //(actual segmentation)

if you look at the example (http://pointclouds.org/documentation/tutorials/cluster_extraction.php#cluster-extraction) it cycles through the indices to insert points into a point cloud (I imagine this is what you want).  So if you wanted a vector of point clouds, you could initialize it and add a level to that example: push back point and then 1 for loop lower, push back cloud. If this doesn't make sense to you/ can't get it working, let me know and I will post some example code Monday.  (I would need to reference my project at work to make sure I post working code though)
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

james
Administrator
In reply to this post by Senf
You can always get the planes, and then segment the indices into clusters (such as euclidean cluster extraction) to eliminate any unrelated points
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Senf
@Polar bear:
I just tried the region growing segmentation. It looks useful but I am somewhat confused on how to use the result for the RANSAC. What I need as an input is a pointcloud. So, how do I get the different pointclouds from the indices vector(clusters)?

@james:
That is what I was trying initially but the planes I got from RANSAC were very unreliable. Sometimes it does not detect planes (even though the points do not change much) and sometimes one plane was detected as multiple.
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Senf
@Polar Bear: Another question concerning your first answer "set up the segmentation to look for that sharp angle at the bottom of each step and overlook the rounded lip". How would you do that? Sorry, for the many questions. :)
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Sneaky Polar Bear
...I don't see much code posted on this forum, but I don't know how else to explain it so here: (to all others please feel free to chastise me if this is poor form as I am not the best coder)


std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> isolatedClouds;
std::vector<pcl::PointIndices> clusterIndices;
/*I left out my particular implementation of the region growing as it is highly application dependent (based on your cloud and scene)*/
        reg.extract(clusterIndices);

        //loop through extracted indicies
        int j = 0;
        for (std::vector<pcl::PointIndices>::const_iterator it = clusterIndices.begin(); it != clusterIndices.end(); ++it) {
                pcl::PointCloud<pcl::PointXYZ>::Ptr cloudCluster(new pcl::PointCloud<pcl::PointXYZ>);
                for (std::vector<int>::const_iterator pit = it->indices.begin(); pit != it->indices.end(); ++pit)
                        cloudCluster->points.push_back(noBackCloud->points[*pit]);

                isolatedClouds.push_back(cloudCluster);

                printf("Cluster found, size: %u\n", cloudCluster->points.size());
                j++;
        }

This code takes the result of the segmentation and places it into a vector of point clouds.

As for the second question.  The two big parameters for region growing are (setSmoothnessThreshold and setCurvatureThreshold).  Smoothness I believe refers to the instantaneous delta between two normal vectors (in radians) and curvature... not exactly sure but I think it is to allow for smoothly curved surfaces (like cylinders).   The other thing you will definitely want to consider is when you compute your normals, how many points you consider in the normal calculation -> more points will result in less noisy normals, but less defined edges and small surface features will get outright ignored, less points will do the exact opposite.  I'm sorry I can't give you a more specific answer for the parameters, but again it is highly dependent on the particulars of your cloud and scene.
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Senf
This post was updated on .
Thank you for the code and all your help. Will try to get this working ;)
Reply | Threaded
Open this post in threaded view
|

Re: Detect steps in a pointcloud with RANSAC

Senf
Another question: I am trying to visualize the planes I get with markers. For this I need a quaternion for the orientation (x,y,z,w). How do I convert the normals I get from the region growing seg. to a quaternion? Are there any function I can use?