最近,OpenCV的Aruco模块进行了更改,其中包括函数的命名和语法。如果您使用的是旧版Aruco代码,并更改为更新的OpenCV版本,则必须相应更改您的代码。这里提供一个示例,其中包含使用新版本Aruco的代码:
import cv2
import cv2.aruco as aruco
# init aruco dict and params
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)
parameters = aruco.DetectorParameters_create()
# reading the image
image = cv2.imread("image.png")
# detect markers in image
corners, ids, rejectedImgPoints = aruco.detectMarkers(image, aruco_dict, parameters=parameters)
# draw detected markers and show result
aruco.drawDetectedMarkers(image, corners, ids)
cv2.imshow("Markers detected", image)
# wait for user key press
cv2.waitKey(0)
在这个示例中,我们初始化了Aruco词典和参数,并使用新版OpenCV中的“detectMarkers”函数来检测图像中的标记,使用“drawDetectedMarkers”函数绘制标记,并使用OpenCV的“imshow”函数将结果显示在窗口中,最后调用“waitKey”以等待用户按键的输入。
这应该可以帮助您开始在更新的OpenCV版本中使用Aruco标记识别。