Physics Stack Exchange is a question and answer site for active researchers, academics and students of physics. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to calculate the distance between two objects using an iPhone camera.

Suppose I'm standing with my iPhone 10 feet away from the objects. Now, I want to calculate the distance between those two objects.

Suppose these two objects are on a straight horizontal line. So, how can I calculate the distance between those two points?

I have only the one predefine value like 10 feet or 5 feet/meter which is the distance between camera and the object.

From the above information how can I calculate the distance between two point OR distance of maximum width of screen ?

Reference Android App: Speed Gun

share|cite|improve this question
Without a stereoscopic view you must either know the distance to the target or find a calibration from pixes/second to linear-distance/second. I am, however, wondering if light field cameras can drag the range out of the data. Wouldn't that be spiffy? – dmckee May 22 '13 at 14:02
I'm slightly confused as to how you can measure the distance from the camera to the objects, but not between them. – Emilio Pisanty May 22 '13 at 19:08
Given the distance between the camera and the object, and a table of parameters about the camera like field of view, I think you CAN calculate the distance between two objects. I think this is almost entirely a geometry / math question though. – Brandon Enright Jun 1 '13 at 1:43

This really depend on all sorts of details, but for the idealized situation, the following data will suffice:

In addition, call the distance between the camera and the two points $L$.

The camera's field of view ($FOV$) (or angle of view as is more common in photography) can be calculated by

$$ FOV = 2\arctan\left(\frac{d}{2F}\right) $$

which, for a scene at distance $L$ corresponds to a scene dimension $W$ equal to

$$ W = 2\cdot L\cdot\tan(FOV/2) = \frac{Ld}{F} $$

therefore, if two objects are $x$ pixels apart, and there are $y$ pixels in that dimension, the objects are

$$ W \cdot \frac{x}{y} = \frac{Ldx}{Fy} $$

meters apart in reality.

As always, make sure you use consistent units; often, the focal lengths will be given in millimeters, while the detector size is given in inches and the distance from the camera to the objects in feet. Choose one system, and convert everything to that single system of units before calculating anything.

Now again, this is a first approximation and only applies to an idealized setup. In reality, there are many other things to consider, but the distance between the objects will roughly follow the relation above.

share|cite|improve this answer
Thanks for the ans. i am going in your way to achieve the functionality. At last i want to calculate the speed like "Speedgun" app which is mention in question. So it will be possible to calculate the speed of object (car) ? – Hitarth May 22 '13 at 9:45
@Coder: Sure, provided you know $L$. How will you know $L$? – Rody Oldenhuis May 22 '13 at 9:46
@Coder: NVM, just read the description of the app :) – Rody Oldenhuis May 22 '13 at 9:47
i input the distance between my Camera to object which is L from the iphone app . NVM ?? – Hitarth May 22 '13 at 9:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.