# Converting ArUco axis-angle to Unity3D Quaternion

I'm interested in comparing the quaternions of an object presented in the real-world (with ArUco marker on top of it) and its simulated version in Unity3D.

To do this, I generated different scenes in Unity with the object in different locations. I stored its position and orientation relative to the camera in a csv file. where quaternions is looking something like this (for one example):

`[-0.492555320262909 -0.00628990028053522 0.00224017538130283 0.870255589485168]`

In ArUco, after using `estimatePoseSingleMarkers`

I got a compact version of Angle-Axis, and I converted it to Quaternion using the following function:

```
def find_quat(rvecs):
a = np.array(rvecs[0][0])
theta = math.sqrt(a[0]**2 + a[1]**2 + a[2]**2)
b = a/theta
qx = b[0] * math.sin(theta/2)
qy = -b[1] * math.sin(theta/2) # left-handed vs right handed
qz = b[2] * math.sin(theta/2)
qw = math.cos(theta/2)
print(qx, qy, qz, qw)
```

where rvecs is the return value of ArUco

However, after doing this I'm still getting way different results, example of the same scene:

`[0.9464098048208864 -0.02661258975275046 -0.009733748408866453 0.321722715311581]`

<< aruco result

`[-0.492555320262909 -0.00628990028053522 0.00224017538130283 0.870255589485168]`

<< Unity's result

Am I missing something?

Validate first your angle-axis <==> quaternion conversion on some test data. In Python, there should be already some available libraries for that.

If the conversion is correct, you have to understand the meaning of the returned [translation + rotation]. For instance, what are the frame of reference for the object coordinates system, for the ArUco coordinate system, for the camera coordinate system, for the Unity coordinates system.

you might also try the reverse - getting axis/angle from your unity quat. if that's not the same, there might be other coord transformations involved in unity.

Hi!

Thanks for your response,

Yes I have tried that but it didn’t work. In both (Unity and ArUco) I’m finding the quaternion relative to the camera. However, I noticed that things get more closer to each others if I change the rotation of the object in Unity to be (-90, 0, 0)

Also, for no apparent reasons, ArUco might find two different quaternions for a marker on the same rotation from the camera, does that make sense?

If I rotate the object in unity by -90, I get to this which is closer but with signs flipped: [-0.941845417022705 -0.0123657090589404 0.00498956767842174 0.335781961679459]