[Physics] Calculate the distance between two points from iPhone Camera

cameradistanceeveryday-lifelensesoptics

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

Best Answer

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.