ARCore Pose and Aruco estimatePoseSingleMarkers

Viewed 1521

I have a server function that detects and estimates a pose of aruco's marker from an image.

Using the function estimatePoseSingleMarkers I found the rotation and translation vector. I need to use this value in an Android app with ARCore to create a Pose.

The documentation says that Pose needs two float array (rotation and translation): https://developers.google.com/ar/reference/java/arcore/reference/com/google/ar/core/Pose.

float[] newT = new float[] { t[0], t[1], t[2] };
Quaternion q = Quaternion.axisAngle(new Vector3(r[0], r[1], r[2]), 90);
float[] newR = new float[]{ q.x, q.y, q.z, q.w };
Pose pose = new Pose(newT, newR);

The position of the 3D object placed in this pose is totally random.

What am I doing wrong?

This is a snapshot from server image after estimate and draw axis. The image I receive is rotated of 90°, not sure if it relates to anything. image server with axis

1 Answers

cv::aruco::estimatePoseSingleMarkers (link) returns rotation vector in Rodrigues format. Following the doc

w = norm( r ) // angle of rotation in radians
r = r/w // unit axis of rotation

thus

float w = sqrt( r[0]*r[0] + r[1]*r[1] + r[2]*r[2] );
// handle w==0.0 separately
// Get a new Quaternion using an axis/angle (degrees) to define the rotation
Quaternion q = Quaternion.axisAngle(new Vector3(r[0]/w, r[1]/w, r[2]/w), w * 180.0/3.14159 );

should work except for the right angle rotation mentioned. That is, if the lens parameters are fed to estimatePoseSingleMarkers correctly or up to certain accuracy.

Related