ARToolKit distance between camera and marker

Hello everyone,

when starting with ARToolKit development I found that it is somehow difficult to understand the transformation matrix and how to retrieve the distance between camera and marker.

Marker transformation matrix

First of all, we need to get the transformation matrix. On Android. for example, you can do that by calling:

float[] markerTransformation = ARToolKit.getInstance().queryMarkerTransformation(markerID)

The variable markerTransformation now contains 16 values that represent the transformation of the marker as seen from the camera. These 16 values represent a 4×4 matrix that might look something like this:

float[16] = [0.24218401, 0.9598883, 0.14125957, 0.0, -0.8614648, 0.2801126, -0.42357886, 0.0, -0.44614935, -0.019116696, 0.8947546, 0.0, 23.678268, -6.4265084, -298.65326, 1.0]

The matrix looks like:

0.24218401

-0.8614648

-0.44614935

23.678268

0.9598883

0.2801126

-0.019116696

-6.4265084

0.14125957

-0.42357886

0.8947546

-298.65326

0.0

0.0

0.0

1.0

How ARToolKit5 sees the world

Now that we have the transformation matrix, the last row is the one that is of interest for us as it contains the x,y and z values. Basically, it comes down to the underlined value in the table. As background, this image illustrates how ARToolKit5 sees the marker:

Marker coordinate system

 

 

 

 

 

 

 

Based on this we can see that the distance between marker and camera is represented by the z-value of the markerTransformation matrix. In our float-array this value is available at position 14. Meaning:

float cameraDistance = markerTransformation[14];

will give you the distance between marker and camera.

Let me know if that works for you and have a look at my StackOverflow article as well.

One Response

  1. financial advisor March 31, 2017