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,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 角點陣列直接套用於兩種偵測器。