How big should an ArUco marker be?
The marker has to cover enough pixels in the image for the detector to find its outline and then read its cells. Everything else follows from that.
The formula
A marker of side S metres, seen straight on at D metres, covers P pixels:
P = f × S / D
f is the focal length in pixels, which is not the focal length in millimetres. If you have not calibrated the camera yet, work it out from the image width and the horizontal field of view:
f = width / (2 × tan(fov / 2))
Rearranged, the printed size you need is:
S = P × D / f
How many pixels the detector needs
OpenCV straightens each candidate marker and samples every cell. The default is four pixels per cell, set by perspectiveRemovePixelPerCell. A 6x6 marker with its border is eight cells across, so the sampling floor is 32 pixels.
That floor assumes a sharp, well lit, straight on marker. Take three times the floor as a working target, and more again if the camera or the marker moves.
Other things that cost you range
A marker seen at an angle is narrower in the image than its true size, roughly by the cosine of the angle. At sixty degrees off straight on you keep half of it.
Motion blur smears cell edges and costs more than distance does. A shorter exposure with more gain often reads better than a clean but blurred frame.
Rolling shutter bends a moving marker, which pushes the corners off and biases the pose. A global shutter camera is worth having if the target moves.
Worked example
A camera 1920 px wide, 60 degree horizontal field of view has a focal length of about 1663 pixels. For a 6x6 marker, which is eight cells wide with its border, the sampling floor is 32 pixels and a working target is 96 pixels.
| Distance | Working size | Absolute floor |
|---|---|---|
| 1 m | 58 mm | 19 mm |
| 2 m | 115 mm | 38 mm |
| 3 m | 173 mm | 58 mm |
| 5 m | 289 mm | 96 mm |
| 10 m | 577 mm | 192 mm |
Range by dictionary
The same 100 mm marker reaches different distances depending on how many bits it carries.
| Bits | Printed width | Cell at 100 mm | Pixels wanted | Range |
|---|---|---|---|---|
| 4×4 | 6 cells | 16.7 mm | 72 px | 2.3 m |
| 5×5 | 7 cells | 14.3 mm | 84 px | 2.0 m |
| 6×6 | 8 cells | 12.5 mm | 96 px | 1.7 m |
| 7×7 | 9 cells | 11.1 mm | 108 px | 1.5 m |