Search code examples
point-cloudspoint-cloud-library

Find points on the line in point cloud


I am using Point Cloud Library. I know there is a function to find lines using RANSAC method, but I want to do opposite of that. I have a point cloud, I have an equation of line, now, I would like to find all the points on or near(within given threshold) the line.

Is there any function/s I can use to achieve my goal?

I would really appreciate any kind of help.


Solution

  • I have attempted to use PCL a few times for Kinect processing but it hasn't worked out too well for me. So I attempted to create my own algorithms to do what I want, and for the application, they work much faster than the PCL ones :)

    The project I am working on is on GitHub and you can find some code that may help in the bool ConvexHull::addPoint(double newX, double newY, double newZ) found here.

    This utilises a 3D plane equation generated using RANSAC and then compares each point to it, calculating the distance between the point and the plane, just like Oscee said.

    Here's the juicy bit of the code which I think may help you:

    // Find the distance from point to plane.
    // http://mathworld.wolfram.com/Point-PlaneDistance.html
    dist  = newX * plane.a;
    dist += newY * plane.b;
    dist += newZ * plane.c;
    dist += plane.d;
    dist /= sqrt(pow(plane.a, 2) + pow(plane.b, 2) + pow(plane.c, 2));
    
    dist = (dist >= 0) ? dist : -dist;  // Absolute distance.
    
    if (dist > tolerance) {
        return false;   // Return false as point is outside of tolerance.
    }
    

    With this function I pass in every point from the 640*480 Kinect image that has a depth value greater than 0.

    And for me, this works quite fast :)

    I hope this helps.