Aruco MarkerDetector会自动去除图像的畸变。它使用摄像机标定参数来校正图像。以下是使用Aruco MarkerDetector进行标记检测的示例代码:
import cv2
import cv2.aruco as aruco
# load camera calibration parameters
calib_data = np.load('calib_data.npz')
camera_matrix = calib_data['camera_matrix']
dist_coeffs = calib_data['dist_coeffs']
# load image
img = cv2.imread('marker_img.png')
# detect markers
aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
parameters = aruco.DetectorParameters_create()
corners, ids, _ = aruco.detectMarkers(img, aruco_dict, parameters=parameters)
# draw markers on image and show
img_markers = aruco.drawDetectedMarkers(img.copy(), corners, ids)
cv2.imshow('Markers', img_markers)
cv2.waitKey(0)
cv2.destroyAllWindows()
在上述示例代码中,calib_data
包含了摄像机的内外参数矩阵,aruco.detectMarkers()
函数会在检测到标识后校正图像,返回校正后的角点坐标。最后,可以使用aruco.drawDetectedMarkers()
函数将检测到的标记绘制在图像上。