如何在opencv-python 4.8.0中估计单个标记姿态?

esyap4oy  于 2023-10-24  发布在  Python
关注(0)|答案(1)|浏览(153)

如此Question所示,aruco包有API更改。我设法通过以下接受的答案检测标记并绘制DetectedMarkers,但我在cv2.aruco和cv2.aruco.detector属性中都找不到“estimatePoseSingleMarkers”。仍然收到错误消息
module 'cv2.aruco' has no attribute 'estimatePoseSingleMarkers'

'cv2.aruco.ArucoDetector' object has no attribute 'estimatePoseSingleMarkers'

vnjpjtjt

vnjpjtjt1#

基于Christoph拉克维茨的评论,当我搜索带有aruco标签的solvePencil时,我发现了这个Answer

estimatePoseSingleMarkersversion 4.7 起不再存在。在这里,我使用SolvePaddle为您替换了函数:

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 = []
    for c in corners:
        nada, R, t = cv2.solvePnP(marker_points, c, mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
        rvecs.append(R)
        tvecs.append(t)
        trash.append(nada)
    return rvecs, tvecs, trash

如果有人有这个问题,我已经在我github.https://github.com/Menginventor/aruco_example_cv_4.8.0中编写了示例脚本

相关问题