Log in or register to post comments

Real distance between marker and camera

November 29, 2012 - 2:01am #1

Hi all,

I've searched on the forum but I didn't find a way to solve my problem: is it possible to know the real distance (in meter) between the camera device and the marker tracked ?

 

Thanks in advance

Real distance between marker and camera

November 4, 2014 - 12:46am #14

Hi, there are a few different ways of getting a reference to a TrackableBehaviour; one possibility is to query the StateManager and obtain the list of current active TrackableBehaviours, as explained in detail here:

https://developer.vuforia.com/forum/faq/unity-how-do-i-get-list-active-trackables

 

Another possibility is to simply create a script and attach it to one of the Trackables in your Unity scene; in the Start method of the script you can then get the TrackableBehaviour component using the GetComponentInChildren<>() Unity method, i.e.:

TrackableBehaviour tb = this.GetComponentInChildren<TrackableBehaviour>();

 

A third approach is to define a script in which your class implements the ITrackableEventHandler (see the DefaultTrackableEventHandler script for an example).

 

Just choose the one that fits best your needs.

 

Real distance between marker and camera

November 3, 2014 - 11:19pm #13

I have an Image target and an object on that image target. I want to calcuate the distance of the AR camera from the tracked object. 

AlessandroB's  Unity script seems to do the job. But where do I put this? In the ImageTargetBehaviour.cs ?

Basically I'm wondering how I will get a reference to the TrackableBehavior objects.

 

Real distance between marker and camera

May 14, 2013 - 10:50am #12

You would need to develop your own based upon the width you've defined and the unit of measure that you want to convert to.

 

For example if you have defined a width of 100 units and want to convert this unit to centimeters, determine the width of your target in centimeters and divide 100 by that value. So if the width in CM is 10, then 100/10 = 10 units per centimeter.

Real distance between marker and camera

May 14, 2013 - 5:34am #11

do you have reference about conversion formula ? or can you give me simple sample how to conversion formula from scale of unity to a standard unit of measure ?

Real distance between marker and camera

May 13, 2013 - 6:51pm #10

The easiest way is to define your target width using the unit of measurement that you'd like to employ - e.g. using the true size of the printed target in mm, cm, inches et.al.

Vuforia applies that unit of measure as the unit scale of the Unity scene.

Otherwise you'll need to define a conversion formula from your scale to a standard unit of measure.

Real distance between marker and camera

May 13, 2013 - 5:58pm #9

thanks for the answer, the distance value showed on Gui, but I want the value in centimeters or meters, how to convert value of variable distance ?

Real distance between marker and camera

May 10, 2013 - 6:43am #8

Hi, in Unity that's quite easy; if you have a reference to one of the TrackableBehaviour objects that you are interested in,

you can do that with some code like this:

Vector3 delta = Camera.main.transform.position - myTrackableBehaviour.transform.position;

float distance = delta.magnitude;

 

Real distance between marker and camera

May 9, 2013 - 8:38pm #7

can i calculate real distance between marker and camera ?, i use Unity extension, sory if i wrong post in this forum

Real distance between marker and camera

December 3, 2012 - 2:38am #6

You're welcome.

Real distance between marker and camera

December 3, 2012 - 2:26am #5

Thanks alot for your reply, it's working perfectly.

Real distance between marker and camera

November 30, 2012 - 12:19am #4

Hi DanieleMobile,

You can also look at the FAQ pointed out by DavidBeard;

the only difference is that in the latter case you don't need to convert your pose matrix (QCAR::Matrix34F) to an OpenGL 4x4 matrix (which would be just an extra unnecessary step). Anyway, both approaches give the same result.

Real distance between marker and camera

November 29, 2012 - 4:19pm #3

Real distance between marker and camera

November 29, 2012 - 8:57am #2

Hi, yes this is possible;

you need to create an ImageTarget and assign it some size when you create it (check the target creation section in the Dev Guide), choosing your preferred unit of measure; for instance you can use millimeters and specify the size in that unit.

Then you need to print the target (for instance on an A4 paper) paying attention that the size of the printed paper target corresponds to the size that you declared for your target when you created it (or you can also manually edit the XML dataset file to adjust the size).

Then run Vuforia ImageTargets sample and get the pose matrix (see ImageTargets.cpp).

If you convert it to OpenGL matrix 4x4 (check code in ImageTargets.cpp), then the distance from the camera (in the unit of measure you had chosen) is given by these matrix values:

float x = matrix.data[12];

float y = matrix.data[13];

float z = matrix.data[14];

float distance = sqrt(x*x + y*y + z*z);

 

 

Log in or register to post comments