Aruco Marker


Last updated: 3 days ago • 4 versions | Visibility: Public

Description

The Aruco marker detection is to position a physical anchor (the marker) in space relative to the main camera in Unity. 

Coordinate system change

In OpenCV the coordinate system is as follow: 

X is to the right, Y to the bottom and Z forward. It is a right handed coordinate system.
On the other hand the unity coordinate system is as follow: 

X is to the right, Y to the top and Z forward. It is a left handed coordinate system.

To be able to correctly position a virtual object on top of the Aruco marker we need to convert the rotation and translation of the Aruco marker relative to the left RGB camera into a rotation and translation in Unity world coordinate space. 

  1. For the translation we need to take two things into account:

    We can then take use the main camera transform to convert the translation relative to the main camera in world space.

    2. For the rotation we need to transform the quaternion in the OpenCV coordinate system to the Unity coordinate system by doing two things

These changes results in the following lines in C#, where translationVector and rotationQuaternion are relatively the translation vector and the rotation quaternion of the marker relative to the left RGB camera given by OpenCV.

 

this.transform.position = Camera.main.transform.TransformPoint(new Vector3(outTransformation.translationVector[0]-(float)0.032,
                                                                           -outTransformation.translationVector[1],
                                                                           outTransformation.translationVector[2]));
this.transform.rotation = Camera.main.transform.rotation * new Quaternion(-(float)rotationQuaternion.x,
                                                                          (float)rotationQuaternion.y,
                                                                          -(float)rotationQuaternion.z,
                                                                          (float)rotationQuaternion.w);