I'm having some trouble understanding how to make use of aruco.estimatePoseSingleMarkers. Currently I have an image or an aruco tag modeled and my camera that is mounted on a drone in Gazebo sim that is flying to the tag. The tag is identified and I estimate the pose of the markers. What I assumed was happening was that TVecs was returning X,Y,Z of the marker in relation to my camera. From that I properly convert the coordinate frames and use that to command my drone. However, I found that the drone using the error moves itself so that the aruco tag is at the 0,0 of the image.
Am I confusing the functionality of the estimatePoseSingleMarker function? What would I need to do to make this work perhaps?
Here is a snippet of the code I'm using. Theres a bit of code to take the camera coordinates and convert them to world coordinate offset from the drone based on the YPR of the drone.
(corners, ids, rejected) = cv2.aruco.detectMarkers(img, self.alg.ARUCO_DICT, parameters=self.alg.ARUCO_PARAMS)
if ids is not None:
for id in ids:
#Set the length of the ID detected.
if(id[0] == 20):
aruco_len = 0.25
#Get the rotation vec and translation vec of the camera to the aruco I believe. can use this to control the quad.
rvecs, tvecs = cv2.aruco.estimatePoseSingleMarkers(corners[0], aruco_len, self.alg.camera_matrix, self.alg.camera_dist)
print tvecs
cam_pts = np.array([[-tvecs[0][0][1]],
[tvecs[0][0][0]],
[tvecs[0][0][2]],
[1]])
print cam_pts
error = self.cam2Local(cam_pts)
def cam2Local(self, cam_pts):
#Here in the function build the Rot matrix of the quadcopter, take XYZ points from camera, [y x z 1] format. Rot_Mat * Cam_Pts will give Aruco wrld pts
roll = self.roll
pitch = self.pitch
yaw = self.yaw
#print str("Pitch: " + str(pitch) + " Roll: " + str(roll) + " Yaw: " + str(yaw))
rot_mat = np.array([[math.cos(roll)*math.cos(pitch), (math.cos(roll)*math.sin(pitch)*math.sin(yaw))-(math.sin(roll)*math.cos(yaw)), math.cos(roll)*math.sin(pitch)*math.cos(yaw)+math.sin(roll)*math.sin(yaw), 0],
[math.sin(roll)*math.cos(pitch), (math.sin(roll)*math.sin(pitch)*math.sin(yaw))+(math.cos(pitch)*math.cos(yaw)), math.sin(roll)*math.sin(pitch)*math.cos(yaw)-math.cos(roll)*math.sin(yaw), 0],
[ -math.sin(pitch), math.cos(pitch)*math.sin(yaw), math.cos(pitch)*math.cos(yaw), 0],
[ 0, 0, 0, 1]])
Local_pts = np.matmul(rot_mat, cam_pts)
#print rot_mat
return Local_pts