1. 快速选型口诀
如果你需要立刻确定默认工程方案,可直接遵循以下四条准则:
远距离小容量优先选 DICT_4X4_50;复杂背景抗误报选 DICT_6X6_250。务必选用满足需求的最小 ID 容量。
首选 AprilTag tag36h11(587 个 ID,汉明距离 11),获得 apriltag_ros、OpenCV 与 pupil-apriltags 的全生态支持。
选 tagStandard41h12(2,115 个 ID,5 格位姿内框)或 tagCustom48h12(42,211 个 ID,内置 2×2 中心镂空可嵌套小码)。
请使用 ETH Kalibr AprilGrid(tag36h11 + 2-bit 黑边 + 外扩角块),而非裸排 AprilTag。
2. 核心架构与指标对比
以下关键差异均经 OpenCV 4.13.0 与 AprilRobotics/apriltag 官方 C 源码核验:
| 对比维度 | OpenCV ArUco | AprilTag 3 经典家族 | AprilTag 3 反转边框家族 |
|---|---|---|---|
| 代表家族 | DICT_4X4_50 .. DICT_7X7_1000 | tag16h5、tag25h9、tag36h11 | tagStandard41h12、tagCircle21h7、tagCustom48h12 |
| 边框极性 | 白边留白区 + 外圈黑边 | 白边留白区 + 外圈黑边 | 内圈白框 + 外圈数据格(中心黑边框界) |
| 角点顺序(0–3) | 顺时针左上起 [TL, TR, BR, BL] | 逆时针左下起 [BL, BR, TR, TL] | 逆时针左下起 [BL, BR, TR, TL] |
| 位姿尺寸基准 | 黑色外框边长(mm) | width_at_border(36h11 为 8 格) | width_at_border(41h12 为 5 格,非外框宽!) |
| 误报抑制策略 | 尽量缩小字典容量(50 优于 1000) | 优先 tag36h11,慎用 tag16h5 | 高汉明距(h=12)+ 反转结构抗杂景 |
3. width_at_border 与 total_width 的位姿尺度陷阱
AprilTag 项目中最常见的 3D 平移测距偏差,源于直接用尺子量取整张标签的外沿总宽,并误填为检测器的位姿基准尺寸(width_at_border)。
AprilTag 单应性求解与 ROS 2 apriltag_ros 的 size 参数对应的是黑白跳变四边形边长 width_at_border,而非完整图纸宽 total_width。tag36h11 含 1 格白边的外宽为 10/8 = 1.25×;反转边框 tagStandard41h12 外宽更达 9/5 = 1.80×!若把 total_width 误填入 apriltag_ros,Z 轴测距会被直接放大 1.80 倍。
4. AprilTag 3 全六大家族参数速查表
以下 6 套 AprilRobotics 官方家族均已被 Movid 生成器与 45 KB WASM 扫描仪完整支持:
| 家族名称 | 可用 ID 数 | 汉明距离 (h) | total_width / width_at_border |
|---|---|---|---|
| tag16h5 | 30 | 5(误报风险偏高) | 8 / 6 = 1.333× |
| tag25h9 | 35 | 9 | 9 / 7 = 1.286× |
| tag36h11 | 587 | 11(机器人默认推荐) | 10 / 8 = 1.250× |
| tagStandard41h12 | 2,115 | 12(反转边框) | 9 / 5 = 1.800× |
| tagCircle21h7 | 38 | 7(圆形排布数据) | 9 / 5 = 1.800× |
| tagCustom48h12 | 42,211 | 12(2×2 中心镂空) | 10 / 6 = 1.667× |
5. 经 CI 实测的 OpenCV 4.13 检测代码
下列两段代码均由 Movid CI 自动运行于矢量 PDF 栅格化样本,保证在 OpenCV 4.13 下零报错运行:
import cv2
# OpenCV >= 4.7 API (tested on OpenCV 4.13.0)
img = cv2.imread("captured_aruco.png", cv2.IMREAD_GRAYSCALE)
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
params = cv2.aruco.DetectorParameters()
params.markerBorderBits = 1 # Set to 2 only if printed with borderBits=2
detector = cv2.aruco.ArucoDetector(dictionary, params)
corners, ids, _ = detector.detectMarkers(img)
print("Detected ArUco IDs:", [] if ids is None else ids.flatten().tolist())
import cv2
# OpenCV 4.x includes built-in AprilTag 36h11 detection via cv2.aruco
img = cv2.imread("captured_apriltag.png", cv2.IMREAD_GRAYSCALE)
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_APRILTAG_36h11)
detector = cv2.aruco.ArucoDetector(dictionary)
corners, ids, _ = detector.detectMarkers(img)
print("Detected AprilTag 36h11 IDs:", [] if ids is None else ids.flatten().tolist())
6. 现场部署四大高频踩坑
16-bit 家族在杂乱场景中的误检
DICT_4X4_1000 与 tag16h5 纠错余量较小。请优先缩减字典规模(如 DICT_4X4_50)或升级至 tag36h11 / DICT_6X6_250。
打印机默认“缩放以适合页面”
PDF 阅读器常把 A4 图纸偷偷缩至约 96%,直接造成 4% 测距系统误差。务必勾选“100% 实际大小”并用卡尺复测 Movid X/Y 双轴核验标尺。
裁剪过紧破坏白色留白区
紧贴黑色边框裁剪会摧毁边缘梯度。标准标记四周应至少保留 1–2 个码元宽度的哑光白色留白区。
混用 ArUco 顺时针与 AprilTag 逆时针角点
OpenCV ArUco 为左上顺时针,AprilTag 为左下逆时针;切勿把同一组 3D 物方角点数组直接套用于两类检测器的 solvePnP。