Log in or register to post comments

display distance in UILabel in ImageTargets Project

January 22, 2013 - 12:00am #1

Hi all ,

I am getting the good output when I am using the ImageTargets Projects  for detecting my logo . Now I have to display the distance in the UILabel . For calculating the distance I have used the below code in the EAGLView.mm .

 

            QCAR::Matrix34F pose = result->getPose();

            QCAR::Vec3F position(pose.data[3], pose.data[7], pose.data[11]);

            float distance = sqrt(position.data[0] * position.data[0] +

                                  position.data[1] * position.data[1] +

                                  position.data[2] * position.data[2]);

            NSLog(@"distance: %f", distance);

 
 

 Kindly tell me in which class I have to add the UILabel code . And what what are the units which I am getting in the distance variable . My Target image size which I have in the database is 247 and the image size on which I have focused the camera is 800 . Please tell me . Thanks in advance .

display distance in UILabel in ImageTargets Project

January 24, 2013 - 4:40am #5

Thank you NalinS

display distance in UILabel in ImageTargets Project

January 23, 2013 - 3:14am #4

Hi srinu4950,

I think David Beard explained the key points in this thread:

https://developer.vuforia.com/forum/android/i-am-getting-distance-fine-values-cm-millimeters-which-format

The scene units are defined using the width value that you provide to the TMS when creating your trackable. So if you have a target that's 10cm wide and define the trackable width as 10, then your scene unit is equivalent to a cm for that target. If you define the trackable width using another unit, such as pixels, you'll need to determine the conversion between pixels and cm for a given target - which would be pixel_width / 10 in this example

So basically Vuforia has no understanding of Units apart from what you supply to it i.e. TMS units

David also adds:

To get the real-world distance of the device from the target you would need to know the printed size of the target. Then you could find the ratio between the defined width of the target and the printed width of the target and use this as a multiplier for the distance. Note that Vuforia has no way of determining the real-world size of the target it is tracking. A 10 inch-wide target and a 5 inch-wide target might track equally well, and look identical to the tracker when the device is moved so the target fills the screen.

So basically you will need to go through a calibration exercise by 1) tweaking the TMS units and 2) calculating this distance multiplier.

HTH

N

BTW it is worth doing a search on "Units"

 

display distance in UILabel in ImageTargets Project

January 22, 2013 - 5:16am #3

Thank you so much . You helped me a lot . One more last question is I have uploaded the 248 pixels width image and my printed image size is 800 pixels . So If I use this method 

 

 

            QCAR::Matrix34F pose = result->getPose();

            QCAR::Vec3F position(pose.data[3], pose.data[7], pose.data[11]);

            float distance = sqrt(position.data[0] * position.data[0] +

                                  position.data[1] * position.data[1] +

                                  position.data[2] * position.data[2]);

            NSLog(@"distance: %f", distance);

 
It is returning the 642 instead of the 2 feet . So please tell me how to change this . I have gone through your link but didn't get what is saying . Sorry for everything .

display distance in UILabel in ImageTargets Project

January 22, 2013 - 4:22am #2

If you try and add the code for the UI Label directly in RenderFrameQCAR it will not work because it gets called in a background thread.

To make it work you need to wrap the code in a method that can get called onthe main thread by using PerformSelectorOnMainThread.

If you search the forums for this you should find some examples as it has come up before.

 

Regarding the point on units, see this thread for more info: https://developer.vuforia.com/forum/qcar-api/how-interpret-scene-units

 

HTH

N

Log in or register to post comments