首页 > 解决方案 > 将 ArUco 的姿势轴绘制到错误的位置

问题描述

我正在研究检测 ArUco 标记并根据这些标记做一些事情的图像处理项目。当视频或图像中只有一个标记时,一切正常,但是当我放置另一个标记时,第二个 ArUco 标记的姿势(轴)打印到错误的位置,而不是标记的中心。请查看我分享的屏幕截图以便更好地理解。

带有 id[2] 的标记很好。姿势轴被绘制到标记的中心。但是,id为1的标记的姿势轴被绘制到某个随机点。

合作

这是检测 ArUco 标记并绘制轴的代码部分。

while True:
    ret, frame = cap.read()

    # Operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)  # Change grayscale
    aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_250)  # Specify marker size as 4x4, 5x5, 6x6
    parameters = aruco.DetectorParameters_create()  # Marker detection parameters
    # Lists of ids and the corners beloning to each marker
    corners, ids, rejected_img_points = aruco.detectMarkers(gray, aruco_dict,
                                                            parameters=parameters,
                                                            cameraMatrix=matrix_coefficients,
                                                            distCoeff=distortion_coefficients)

    try:    
        if np.all(ids is not None):  # If there are markers found by detector
            for i in range(0, len(ids)):  # Iterate in markers
                # Estimate pose of each marker and return the values rvec and tvec---different from camera coefficients
                rvec, tvec, markerPoints = aruco.estimatePoseSingleMarkers(corners[i], 0.02, matrix_coefficients,
                                                                           distortion_coefficients)
                (rvec - tvec).any()  # get rid of that nasty numpy value array error
                aruco.drawDetectedMarkers(frame, corners)  # Draw A square around the markers
                aruco.drawAxis(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01)  # Draw axis

                c_x = (corners[i][0][0][0] + corners[i][0][1][0] + corners[i][0][2][0] + corners[i][0][3][0]) / 4 # X coordinate of marker's center
                c_y = (corners[i][0][0][1] + corners[i][0][1][1] + corners[i][0][2][1] + corners[i][0][3][1]) / 4 # Y coordinate of marker's center
                cv2.putText(frame, "id"+str(ids[i]), (int(c_x), int(c_y)), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (50,225,250), 2)

    except:
        if ids is None or len(ids) == 0:
            print("******************************************************")
            print("*************** Marker Detection Failed **************")
            print("******************************************************")

标签: pythonopencvimage-processingcomputer-visionaruco

解决方案


推荐阅读