A camera image isn't a map
A camera mounted high and looking down at an angle sees the floor in perspective. Near the camera, one pixel might cover half a centimetre. At the far edge it might cover several centimetres. Draw a zone straight on the image and it's the wrong shape on the real floor; measure a distance in pixels and it means something different everywhere in the frame.
For anything that has to act on positions, like keep-out zones around a machine, distance between a forklift and a person, or how long a pallet sits in a lane, you need floor coordinates, not pixels.
A homography is the fix for a flat floor
When everything you care about is on one flat surface, the relationship between image pixels and floor positions is a homography: one 3 by 3 matrix. You find it from four points whose floor positions you know, for example four markers measured with a tape, and their pixel positions in the image.
In the figure, the four markers sit at the corners of a 3 by 2 m area on a 4 by 3 m floor. The camera sees them at pixels like (451, 617) and (518, 257). From those four pairs the homography is solved, and from then on every foot pixel maps straight to metres on the map. One pixel is about 0.5 cm near the camera and 1.2 cm at the far side.
Use the feet, not the box centre
A homography only holds for points on the floor. The centre of a person's bounding box is a metre above it, so mapping it gives the wrong position, worse the further away they stand. The right point is the bottom centre of the box, where the feet touch the floor. Small detail, large effect on where the zone trips.
What I do on site
- Put down markers or use existing floor features, and measure them with a tape or laser.
- Spread the four or more points across the whole area you care about, not one corner.
- Check the result by mapping a few extra known points and measuring the error.
- Draw zones on the floor map, not on the image, so they're the right shape in reality.
- Recalibrate if the camera is moved or bumped. Log a reference image to make that obvious.