Skip to content

johnathanmitri/MeasureDistance

Repository files navigation

MeasureDistance

If you know the height of an object, you can get your distance from it using only your device's camera.

Native Android app written in Java, and published to the Google Play Store.

Tested on Pixel 6a, Galaxy A50, and Galaxy J3 with ~ 98% accuracy

How to Use

  1. Enter the height of the object
  2. Hold your device level
  3. Select the top and bottom of the object on screen
  4. The device's distance from the object is calculated automatically

Demo

Calculations explained:

- theta: Camera FOV (Retrieved from Camera API)
- h: represents the full height that can be seen with the camera at the given distance
- s: physical height (size) of the object
- d: distance from the object

-The ratio of the Full Screen to the Object on screen can be calculated using pixels
   -example ratio:  1920 : 960  =>  Therefore, h = (1920/960) * s.

-If the object takes up half the screen, then h is twice the size of the object.

-tan(theta/2) can be considered constant when not zooming

-(h/2) / d = tan(theta/2)

-Therefore, d = (h/2)/tan(theta/2), where h = (physical height of object) * (total screen height) / (object height on screen)

This requires the camera to be perpendicular to the object. If the camera is not perpendicular it will be inaccurate.

Here's a crude drawing for reference:

visualization

About

Measures distance from an object using the camera

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages