0

I need a program to estimate the pose of an ArUco marker, and, as far as I know, I can code it with two different functions: cv2.solvePnp() or cv2.aruco.estimatePoseSingleMarker(). Which one is better? I read about them, and it seems easier to use cv2.aruco.estimatePoseSingleMarker(), but is it as accurate as cv2.solvePnP()? Thanks

I am a graduating student, and I need this information because I am doing a research with a teacher.

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
Matheus
  • 3
  • 2

1 Answers1

3

estimatePoseSingleMarkers no longer exists as of version 4.7. Here, I replaced the function for you using SolvePnP:

def my_estimatePoseSingleMarkers(corners, marker_size, mtx, distortion):
    '''
    This will estimate the rvec and tvec for each of the marker corners detected by:
       corners, ids, rejectedImgPoints = detector.detectMarkers(image)
    corners - is an array of detected corners for each detected marker in the image
    marker_size - is the size of the detected markers
    mtx - is the camera matrix
    distortion - is the camera distortion matrix
    RETURN list of rvecs, tvecs, and trash (so that it corresponds to the old estimatePoseSingleMarkers())
    '''
    marker_points = np.array([[-marker_size / 2, marker_size / 2, 0],
                              [marker_size / 2, marker_size / 2, 0],
                              [marker_size / 2, -marker_size / 2, 0],
                              [-marker_size / 2, -marker_size / 2, 0]], dtype=np.float32)
    trash = []
    rvecs = []
    tvecs = []
    i = 0
    for c in corners:
        nada, R, t = cv2.solvePnP(marker_points, corners[i], mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
        rvecs.append(R)
        tvecs.append(t)
        trash.append(nada)
    return rvecs, tvecs, trash
user1270710
  • 553
  • 1
  • 6
  • 11
  • I'm having trouble to use the output of this replacement function. I'm getting (with a 4.5 OpenCV): OpenCV(4.5.5) /Users/runner/work/opencv-python/opencv-python/opencv/modules/calib3d/src/calibration.cpp:605: error: (-5:Bad argument) Rotation must be represented by 1x3 or 3x1 floating-point rotation vector, or 3x3 rotation matrix in function 'cvProjectPoints2Internal' The output structure of the arrays is different, compared to the output of estimatePoseSingleMarkers. – decades May 18 '23 at 14:24