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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With