opencv 求解PnP或估计姿势单个标记:哪个比较好?

yi0zb3m4  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(171)

我需要一个程序来估计ArUco标记的姿态,据我所知,我可以用两个不同的函数来编写它:cv2.solvePnp()cv2.aruco.estimatePoseSingleMarker()。哪个更好?我读过他们,似乎更容易使用cv2.aruco.estimatePoseSingleMarker(),但它是一样准确的cv2.solvePnP()?谢谢
我是一名即将毕业的学生,我需要这些信息,因为我正在和一位老师做一项研究。

ewm0tg9j

ewm0tg9j1#

estimatePoseSingleMarkersversion 4.7 起不再存在,这里我用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

相关问题