Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Camera Position and Rotation using Aruco Markers

I used the function cv.aruco.estimatePoseSingleMarkers() to get rvec and tvec. Using these two vectors how can I get the camera pose relative to the Aruco Marker?

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

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    aruco_dict = aruco.Dictionary_get(aruco.DICT_ARUCO_ORIGINAL)
    parameters = aruco.DetectorParameters_create()

    corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)

    font = cv2.FONT_HERSHEY_SIMPLEX 

    if np.all(ids != None):
        # POSE ESTIMATION
        rvec, tvec,_ = aruco.estimatePoseSingleMarkers(corners[0], 0.1, mtx, dist) 
like image 952
Xron7 Avatar asked Nov 15 '25 20:11

Xron7


1 Answers

rvec is the rotation of the marker relative to the camera frame. You can convert rvec to a rotation matrix using the built-in Rodrigues function. Then get the inverse of this matrix (this is a rotation matrix, so the inverse is the transpose of the matrix). This is the rotation of the camera with respect to the marker.

Magnitude of the tvec is not affected by the rotation. If you need to consider the direction of the camera relative to the marker, just take the negative of tvec.

like image 127
Kani Avatar answered Nov 18 '25 09:11

Kani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!