Aruco Marker
Last updated: 24 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.
- For the translation we need to take two things into account:
- The coordinate changes so we need to take the opposite of the Y value given by OpenCV
- The main camera in Unity is situated between the two RGB cameras which are 64mm appart. We therefore need to remove 32mm on the X value given by Opencv
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
- First take the opposite of the Y value
- As there is an odd number of opposites (linked to the fact that the coordinate system becomes left handed) we need to take the opposites of the x, y, and z values
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);