Depth & Point Clouds, step 3
Finding the table
Fit the table's plane with RANSAC, even though objects cover it and the camera's calibration is slightly off, then measure heights from it.
The table isn't where you think
The table top is in the robot's frame, so "keep points with cm" ought to separate the objects from the table. But that only works if camera.pose is perfect, and no calibration is. From this step on, the pose you're given is off by a degree or so, as real ones are. A 1° error tilts the table in the cloud by 9 mm over half a metre, and here it also sits up to 1.5 cm too high or too low. Look at the grey points in the 3-D view: they float above the real table on one side and sink into it on the other.
So don't assume where the table is: measure it. A plane is with a unit normal; a point's signed distance from it, , is its height above the table.
RANSAC
Least squares on every point is dragged towards the objects. RANSAC (random sample consensus) ignores them:
- Pick 3 random points . Their plane has normal , normalised (skip it if that's nearly zero: the points are in a line).
- Count the inliers: points with
threshold(5 mm, a few times the noise). - Repeat, keeping the plane with the most inliers.
- Refit to those inliers. That's
pca_normalfrom step 2 again: the table's normal is its direction of least spread. Then , with the inliers' mean.
Make point up (), so heights above the table come out positive.
How many tries? If a fraction of the points are table, one sample is all table with probability . With , 100 tries all miss with odds below .
Your task
Write fit_plane(points, threshold, iters) returning (n, d). The program colours the table grey and the objects blue, compares with a plain threshold, and hovers the fingertips 2 cm above the tallest object, using its height above your plane.
The grader also tests fit_plane on three tilted synthetic tables and on a new image from this camera.