ArUco Markers
ArUco markers are binary square fiducial markers used for camera-based pose estimation.
Installation
bash
pip install opencv-contrib-pythonDetect Markers
python
import cv2
import cv2.aruco as aruco
import numpy as np
cap = cv2.VideoCapture(0)
aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)
params = aruco.DetectorParameters()
detector = aruco.ArucoDetector(aruco_dict, params)
while True:
ret, frame = cap.read()
corners, ids, _ = detector.detectMarkers(frame)
if ids is not None:
aruco.drawDetectedMarkers(frame, corners, ids)
print("Detected IDs:", ids.flatten())
cv2.imshow("ArUco", frame)
if cv2.waitKey(1) == ord('q'):
breakPose Estimation
python
# Camera calibration matrices (from calibration step)
camera_matrix = np.array([[fx, 0, cx],[0, fy, cy],[0, 0, 1]])
dist_coeffs = np.zeros((5,1))
marker_size = 0.05 # metres
rvecs, tvecs, _ = aruco.estimatePoseSingleMarkers(
corners, marker_size, camera_matrix, dist_coeffs)TIP
Print markers at exactly the size you specify as marker_size. Physical size accuracy directly affects translation accuracy.