AprilTag

On this page 7

AprilTag is a visual fiducial marker system of printed black-and-white square codes that a camera can detect, identify by a unique numeric ID and use to compute the full 3D position and orientation of the tag relative to the camera. In robotics perception, AprilTags provide reliable ground-truth landmarks for localization, calibration and object tracking where natural features are unreliable.

The system was developed at the University of Michigan APRIL laboratory and has evolved through several versions, with AprilTag 3 as the current reference library. Its strength lies in a low false-positive rate, robustness to lighting changes and partial distortion, and an open-source implementation that runs in real time on modest hardware.

How AprilTag detection works

AprilTag detection is a pipeline that turns a grayscale image into a list of tag IDs with corner coordinates. The detector first applies adaptive thresholding to separate dark and light regions, then groups boundary pixels into connected contours and fits quadrilaterals to candidate shapes.

For each quad, the detector computes a homography that maps the tag’s ideal square onto the image, samples the interior grid of cells and reads the resulting bit pattern. The pattern is compared against the tag family codebook using Hamming distance, which allows correction of a few flipped bits and rejects patterns that match nothing.

Finally, given the camera intrinsics and the physical tag size, a perspective-n-point solver estimates the tag pose. The table below lists the main stages.

StageInputOutput
Adaptive thresholdingGrayscale imageBinary light and dark regions
Quad fittingRegion boundariesCandidate quadrilaterals
DecodingHomography-sampled cellsBit pattern and tag ID
Pose estimationCorners, intrinsics, tag size6D pose of the tag
RefinementImage edgesSubpixel corner positions
Stages of the AprilTag detection pipeline

AprilTag families and their trade-offs

An AprilTag family defines the grid size, the number of valid codes and the minimum Hamming distance between any two codes. Larger grids store more IDs, while a higher minimum distance makes misidentification less likely but leaves fewer usable codes.

FamilyData bitsValid IDsMinimum Hamming distance
tag16h516305
tag25h925359
tag36h113658711
tagStandard41h1241211512
tagCircle21h721387
Common AprilTag families

The tag36h11 family is the usual default because it balances ID count, robustness and readable cell size. The small tag16h5 family is easy to detect at long range but yields more false positives, so applications that use it should filter detections by decision margin. Newer layouts such as tagStandard41h12 place data bits outside the border, enabling recursive tags nested within one another.

AprilTag compared with other fiducial markers

AprilTag belongs to the broader class of fiducial markers, artificial patterns designed for machine detection. Its closest relatives are ArUco markers, which use a similar square layout, and QR codes, which store far more data but are not optimized for pose estimation at distance.

Marker typeMain purposeStrengthWeakness
AprilTagPose and IDVery low false-positive rateHigher compute than ArUco
ArUcoPose and IDFast and built into OpenCVMore false positives in clutter
ChArUco boardCamera calibrationAccurate checkerboard cornersNeeds a full board in view
QR codeData storageLarge payloadPoor at range and oblique angles
Retroreflective markerMotion capturePrecise with IR camerasRequires special lighting
Fiducial marker systems used in robot perception

Unlike natural-feature methods in visual odometry or Visual SLAM, a tag gives an unambiguous identity for each landmark, which removes the data association problem and simplifies loop closure in small mapped areas.

Practical use of AprilTags in robot perception

AprilTags are used wherever a robot needs cheap, reliable pose references without a full motion-capture system. Common tasks include docking a mobile robot to a charger, hand-eye calibration of an arm-mounted camera, localization in warehouses, and benchmarking SLAM algorithms against known landmark positions.

Accuracy depends strongly on the apparent tag size in pixels, camera calibration quality and viewing angle. As a rough guide, the decoded tag should span at least 20 to 30 pixels across for reliable detection, and pose accuracy improves greatly when several tags are combined into a tag bundle with known relative positions.

SettingTypical choiceEffect
quad_decimate1.0 to 2.0Faster detection, shorter range
quad_sigma0.0 to 0.8Blur to suppress image noise
refine_edgesEnabledBetter corner accuracy
Decision margin filterAbove 30 to 50Rejects weak, doubtful detections
Tag size parameterMeasured black border widthCorrect metric scale of pose
Configuration choices and their effect

The tag size must be measured on the outer edge of the black border, not the white margin, because an incorrect size scales every translation estimate proportionally.

Limitations and common mistakes

AprilTag detection is robust, but several failure modes recur in practice, most of them caused by setup rather than by the algorithm.

  • Pose ambiguity occurs when a small tag is viewed nearly head-on, so the solver may flip between two orientations; tag bundles or temporal filtering reduce it.
  • Motion blur and rolling-shutter distortion break quad fitting on fast-moving robots; short exposure times help.
  • Glossy printing causes specular reflections that erase cells; matte paper or laminate is preferable.
  • Poor camera calibration biases every pose estimate, regardless of detection quality.
  • Missing white margin around the tag prevents the border from being segmented.

Tags also require modifying the environment, which is not always acceptable in homes, public spaces or outdoor fields, and they carry only an ID rather than rich semantic information.

In simple terms

An AprilTag is a printed square with a black-and-white pattern, similar to a simple QR code. A robot camera can spot it quickly. The pattern tells the robot which tag it is looking at.

The shape of the square in the image also reveals where the tag is and how it is tilted. Think of a road sign that tells a driver both its name and its exact location. The main benefit is certainty: the robot knows precisely what it sees, even in a messy room.

A practical example

A hospital uses small autonomous carts to deliver linens and supplies between floors. Each cart must return to a charging dock in a narrow corridor and align within about one centimeter so that its contacts touch the charger plates. Lidar alone struggles because the dock looks like a plain wall.

Engineers mount a 15 cm tag36h11 AprilTag above each dock and calibrate the cart camera carefully. During the final two meters of approach, the cart detects the tag at 30 frames per second, estimates its pose and steers along a straight line to the contacts. After deployment, docking success rises to nearly every attempt, and failed charging events drop sharply, with tags replaced only when they become scratched.