# Phone camera (Samsung S4): is it possible to determine the distance to the object in focus on jpg picture?

I took a picture with Samsung S4 phone. Is it possible to determine the distance to the object on the picture?

The object is in focus. I looked at the JPG picture properties but could not find anything indicating to the distance. The focal length is fixed on this camera, it's 31mm in 35mm equivalent scale.

• Do you know the size of the object? Apr 12, 2014 at 11:29
• @mattdm, no. In fact the reason I'm looking for a distance is to determine the size Apr 12, 2014 at 13:56
• That makes a big difference to the answers. Apr 12, 2014 at 14:04

You can use this equation:

Distance of an object (in meters) =

(focal length (mm) * object height (m) * image height (px))
-----------------------------------------------------------
(object height in image (px) * sensor height (mm))

• See the comments. Size of object is not known. Apr 12, 2014 at 14:04
• @mattdm ah! well 2 unknown variables is a a problem, hope OP can estimate one of them. gotta work with what you have! Apr 12, 2014 at 17:02

If it is in the file, exiftool will tell you.

If not, there is no easy way to tell the distance as cameras basically record angle information (in the picture - each pixel looks at a specific direction from an idealized center). If you have two or more photos from different viewpoints, then you could use PanoTools or similar tools to create a 3D mesh, and if you know some physical lengths then you could derive the distance to your object. (And you know some physical locations: your eye or camera level, and also the ground level, let's not forget it).

• thanks, i'm surprised that cameras do not record auto-focus information. Apr 10, 2014 at 15:17
• Well - they record focal length and in-focus indicators. :-) But distance to subject needs triangulation, so two pictures. Apr 10, 2014 at 15:33
• @TFuto - it doesn't need triangulation. It does however need to know the exact stetting of the focus and the atmospheric conditions. Focus can change slightly based on humidity and such and generally lenses don't measure the exact position of the focus. If you did know the exact setting of the focus though, then the distance to subject can be calculated without any triangulating. Apr 10, 2014 at 19:50
• @AJHenderson: Your reasoning is only valid if the person uses an extremely shallow depth-of-field, like one in microscopes (a long teleobjective is a good approximation). If he is using large DOF and not long focal length, the successive approximation or heuristics of focusing just gets a good enough focus lock. Imagine a very extreme scenario: an ultra wide angle lens. That has focus from 30 cm to infinity. So okay, you have a focus lock, but the relative error is so big, that data is not useful. My opinion... Apr 10, 2014 at 20:25
• Ah using the relative angles it the scene to determine relative angle. OK. I'm on board now. Apr 10, 2014 at 22:18

Most lenses don't measure the position of the focus, just which direction they need to move in order to reach focus. Therefore they can't measure the exact position of the focus. If the data isn't already in the EXIF information of the photo, then it likely is not able to be captured by the camera.

• it makes a sense then, i was wondering why don't they report the position of the focus. i'd love to look at low level specifications of the phone cameras Apr 10, 2014 at 19:36