# Convert Quaternion from Unity3D to OpenCV

Hello,

I’m using Unity3D to simulate a real-world environment I have. In the real world, I have a camera calibrated with ArUco and OpenCV (which is right-handed) and an ArUco marker on top of the object.

In Unity, I have the exact same scene.

ArUco returns for me both the object translation and orientation relative to the camera frame. For the translation, it was easy since the only thing I have to change is inverting the y-value and it turned out to be accurate. Quaternion, on the other hand, is more tricky. I couldn’t come up with a direct conversion!

I’ve been googling this for days with no luck. The values I’m getting from both are different. Example here (for the same cube position and orientation):

ArUco’s value: [x,y,z,w] = [0.8459557461269711, -0.38441595943481305, 0.15413126405888497, 0.3358970067836006]

Unity’s: [x,y,z,w] (found by cube.transform.localRotation = [-0.300987899303436, -0.321731448173523, 0.100743912160397, 0.892045915126801]

Small errors (like 0.05) is expected because I can’t be 100% sure that camera position in the real world is the same as Unity. But still, the two vectors are completely different!

BTW: my camera in Unity is at position [x,y,z] = [0,0.5,0] and the cube is at [0,0, 0.5]. And I’m only rotating the camera not the cube (by detaching the child and re attaching it after)

Am I missing something?

I’m trying to get this working as well. My cubes are just floating round the markers though. How did you get your object to stick to the marker?
What does your code look like? How are you currently converting to Quaternions?

I didn’t understand your problem entirely tbh.

But I found that when the marker is perpendicular to the cube then it’s indeed in 90 degrees rotation, so I had to change the pivot point of the cube to be the rotated with 90 degrees and to be the top of the cube, not its centre.

As for quaternions conversion.

Q(Unity) = (-x, y, -z, w) of the openCV one.

Hope this helps.