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

  • $\begingroup$ 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? $\endgroup$ May 22, 2013 at 14:02
  • 1
    $\begingroup$ I'm slightly confused as to how you can measure the distance from the camera to the objects, but not between them. $\endgroup$ May 22, 2013 at 19:08
  • $\begingroup$ 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. $\endgroup$ Jun 1, 2013 at 1:43

1 Answer 1


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.

  • $\begingroup$ 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) ? $\endgroup$
    – Hitarth
    May 22, 2013 at 9:45
  • $\begingroup$ @Coder: Sure, provided you know $L$. How will you know $L$? $\endgroup$ May 22, 2013 at 9:46
  • $\begingroup$ @Coder: NVM, just read the description of the app :) $\endgroup$ May 22, 2013 at 9:47
  • 1
    $\begingroup$ i input the distance between my Camera to object which is L from the iphone app . NVM ?? $\endgroup$
    – Hitarth
    May 22, 2013 at 9:53
  • $\begingroup$ @Coder: internetslang.com/NVM-meaning-definition.asp $\endgroup$ May 22, 2013 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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