CrackRobotics

Step 1

RANSAC

Fit a plane to a depth image full of other objects by trying many tiny samples and keeping the one most points agree with.

What it computes

Least squares fits a model to all the data, so a few wild points can drag it anywhere. RANSAC (random sample consensus) is built for data full of outliers: it finds the model that the largest number of points agree with, and ignores the rest.

The algorithm

A plane needs only three points. So:

best = none
repeat iters times:
    pick 3 random points a, b, c
    n = (b - a) x (c - a), normalised    # skip if the points are in a line
    d = -n . a                           # the plane n . p + d = 0
    inliers = |points . n + d| < threshold
    keep (n, d, inliers) if it has more inliers than best
refit n, d to best's inliers with least squares

For the refit, centre the inliers on their mean pˉ\bar p. The normal is then the direction of least spread: the last row of VTV^T from np.linalg.svd(inliers - p_mean). Finally d=−n⋅pˉd = -n \cdot \bar p.

How many iterations? If a fraction ww of the points are inliers, one sample is all-inlier with probability w3w^3. After kk tries you miss every time with probability (1−w3)k(1 - w^3)^k. For w=0.6w = 0.6, 200 tries miss with probability below 10−1010^{-10}.

The program

The camera on its stand has been bumped to an unknown pose. The program turns its depth image into 3-D points in the camera's frame, and adds 2 mm of noise, as a real depth sensor would. Most of the points are table; the rest are balls, the cup, the floor and the robot. Your plane gives the camera's height (∣d∣|d|) and its tilt from vertical, and your inliers are shown in the Images tab.

Your task

Implement ransac_plane(points, threshold, iters). It returns (n, d, inliers): a unit normal, an offset, and a boolean mask with one entry per point. The grader also runs it on three synthetic clouds with 40% outliers.

Goals

  • Program runs without errors
  • On 3 test clouds with 40 % outliers: normal within 1°, offset within 2 mm, inliers ≥ 95% right
  • From the table plane: camera height within 3 mm and tilt within 0.5° of the truth
Loading physics…
Loading 3D view…
0.0 / 0.0 s

Python is loading. It takes a few seconds the first time.