Depth & Point Clouds, bonus step
Bonus: Let the table fix the camera
Use the fitted table to correct the camera's pose itself, so every point's z is its true height, and see which errors a plane can't reveal.
Fix the camera, not every height
In step 3 you measured every height from the fitted table. You can go one better and use the table to correct camera.pose itself: then every point comes out right, with no plane to carry around.
The fitted plane is where the table appears. You know where it really is: , with normal . The correction is the rigid motion that lays the one on the other.
Turning one vector onto another
The smallest rotation that turns the unit vector onto turns about their cross product . With , the cosine of the angle between them,
where is the matrix with . No trigonometry, and an already level table () gives and .
After that rotation the table is the plane , so lift everything by . is the 4 × 4 matrix with in its top-left corner and as its translation. The camera's view goes into the world as it believed and then gets corrected, so the fixed pose is .
What a plane can't tell you
A flat table looks the same however you slide the camera along it or turn it about the vertical. So the plane pins only three of the pose's six numbers: two tilts and the height. That's enough here, because this camera's error is a tilt and a shift up or down. To find the other three you need something with corners, like the box of step 5, or the hand-eye calibration of Seeing with a Camera.
Your task
Write level_pose(T, n, d), returning the corrected 4 × 4 pose. The program stores it as fixed, rebuilds the cloud with it, checks that the table now lies flat at , and hovers the fingertips 1 cm above the tallest object using nothing but its .