Step 1
Linear systems: calibrate a camera
A camera that reports pixels, three known points and six unknowns: solve Ax = b to turn pixels into metres.
A camera that speaks pixels
A new camera, overhead, hangs high above the table looking straight down. It finds every ball, but it reports pixels : column and row of a 640 × 480 picture. Where the camera hangs and how it's turned change every run, and world.balls() is switched off. To use the camera you have to calibrate it: work out how pixels turn into metres.
The map is linear
Because the camera looks straight down, points at one height (such as the balls' centres, 2.5 cm up) appear as a scaled, rotated and shifted copy of the table:
That's six unknown numbers, to . Each is only multiplied by something you know (, or 1) and added up, so these are linear equations. In matrix form, with a 2×3 matrix:
Three points pin it down
Put the gripper on a pad whose table position you know, and overhead.marker() gives the pixel of a marker at the grasp point. The map only holds at one height (things closer to the camera look bigger), so read the marker with the grasp point at ball-centre height, where the pads are. Each pad gives two equations; three pads give six, one for each unknown. The x-equations only involve , and :
The y-equations use the same with , , and the . A square system (unknowns , known right-hand side ) has exactly one answer when its equations are independent, and np.linalg.solve(M, r) finds it.
If the three pads lie on one straight line, one row of is a mix of the other two. The equations repeat each other, is singular, and there's no single answer. Keep calibration points spread out.
Seeing with a Camera, step 1 builds the full camera model behind this map.
Your task
- Write
solve_affine(pixels, points).pixelsholds three[u, v]rows andpointsthree[x, y]rows. Return the 2×3 matrix . - The starter visits the three yellow pads (
world.targets()) at ball height and records the marker's pixel on each. - Convert the red ball's pixel (
overhead.balls()["red"]) to table coordinates with , and put the ball in the cup.