How to Measure Distance to Object With Camera

Is it possible to measure distance to object with camera?

Well you should read how ithinkdiff.com "measures" the distance:

Uses the angle of the iPhone to estimate the distance to a point on the ground.
Hold the iPhone in front of you, align the point in the camera and get a direct
reading of the distance. The distance can then be used in the speed tool.

So basically it takes the height of where you hold the phone (eye-level), then you must point the camera to the point where object touches the ground. Then the phone measures the inclination and with simple trigonometry it calculates distance.

This is of course not very accurate. It gets less accurate the further the object is. Also it assumes that the ground is level.

How can I determine distance from an object in a video?

When you have moving video, you can use temporal parallax to determine the relative distance of objects. Parallax: (definition).

The effect would be the same we get with our eyes which which can gain depth perception by looking at the same object from slightly different angles. Since you are moving, you can use two successive video frames to get your slightly different angle.

Using parallax calculations, you can determine the relative size and distance of objects (relative to one another). But, if you want the absolute size and distance, you will need a known point of reference.

You will also need to know the speed and direction being traveled (as well as the video frame rate) in order to do the calculations. You might be able to derive the speed of the vehicle using the visual data but that adds another dimension of complexity.

The technology already exists. Satellites determine topographic prominence (height) by comparing multiple images taken over a short period of time. We use parallax to determine the distance of stars by taking photos of night sky at different points in earth's orbit around the sun. I was able to create 3-D images out of an airplane window by taking two photographs within short succession.

The exact technology and calculations (even if I knew them off the top of my head) are way outside the scope of discussing here. If I can find a decent reference, I will post it here.

how can we measure distance between object and android phone camera

Your getRotationMatrix is probably returning false! You should copy the values to your own vectors so they don't get mixed up! Use the clone() method to do so!

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
gravity = event.values.clone();
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
geoMagnetic = event.values.clone();

Using your code plus this change I was able to get the azimuth/pitch/roll values, without this change the success flag returns false:

Log.d("a", "orientation values: " + azimut + " / " + pitch + " / " + roll);
05-21 16:07:55.743: D/a(29429): orientation values: 77.71578 / 43.352722 / -152.39603
05-21 16:07:55.883: D/a(29429): orientation values: 175.26134 / 23.031355 / -148.72844
05-21 16:07:56.793: D/a(29429): orientation values: -146.3089 / 4.1098075 / -14.46417

You should use the PITCH value if you are holding the phone in portrait mode, if you are holding the phone in landscape mode you should use the ROLL value.

If you are holding the phone at a 1.4 height then you will have:

float dist = Math.abs((float) (1.4f * Math.tan(pitch * Math.PI / 180)));

Please note that you should use RADIANS and not DEGREES on the Math.tan function.

I tested here and the values seem to be valid!

Finding distance from camera to object of known size

You can use triangle similarity to calibrate the camera angle and find the distance.

You know your ball's size: D units (e.g. cm). Place it at a known distance Z, say 1 meter = 100cm, in front of the camera and measure its apparent width in pixels. Call this width d.

The focal length of the camera f (which is slightly different from camera to camera) is then f=d*Z/D.

When you see this ball again with this camera, and its apparent width is d' pixels, then by triangle similarity, you know that f/d'=Z'/D and thus: Z'=D*f/d' where Z' is the ball's current distance from the camera.

How to measure distance of object using camera?

ok you have to

1-drow a "+" or "." in the center of the screen
why ? the bottom of the object that you need to calculate distance from it must be in that "+"

2-access to the G-sensor to know the angle of inclination of the phone (sorry for my english)

3-use a fixed height .. for example the phone must be 1.5 meters of the ground

4-here mathematics get in.. you have angle .. and height ..you can calculate the distance between you and the object.

now you know the steps just translate them to a running application

Sample Image



Related Topics



Leave a reply



Submit