how to get Distance of Object from iPhone camera using image Exif meta data? how to get Distance of Object from iPhone camera using image Exif meta data? objective-c objective-c

how to get Distance of Object from iPhone camera using image Exif meta data?


@iphonemaclover. As many people have pointed out there's insufficient information to calculate this purely using trigonometry. However, depending on how accurate you need to be, or what it is you're trying to measure and other data you can expect to recover from an iphone and/or you're willing to make some assumptions, it is possible to make some inroads.

a) +1 to Martin R, if you assume a flat earth, a phone height (which as per the app you quoted) a user could update for calibration purposes, can recover pitch information and know where a point on the ground at the base of your object is then this is simple trig. Once there's a estimate for the distance and assuming the thing you're measuring is close to vertical (or sits at a known angle) then its height can also be calculated.

b) Your exif file contains face region information. If you're interested in people and are happy to make an assumption that they're an adult then you could use an average head size assumption to estimate distance using the method you've outlined already.

c) If you can recover a series of images and camera positions and the camera / object positions vary then I believe that 3d information can be recovered using projective geometry.


If you're wondering how to find distance given the phone/tablet height and pitch up/downward, just use the atan of the angle downwards (0 if it is pointed forward; -30 if it is -30 degrees downwards) times the height.The only problem is, we don't know the phone height off the ground.

I know you want to use the focus of the camera, but that is improbable. You mentioned an android app, while if you'll notice that app requires you to enter phone height off the ground. You could try using GPS altitude minus what a topographic map says, but that is incredibly inaccurate. Or maybe you could take a picture from one location, then move around the target by 45 degrees or so, but not everyone has a compass to measure that or has the ability to run circles around the target. How would you move 45 degrees around a object in front of you while standing on a bridge? Even if you did try to use the camera focus, that is automatically updated and I know nothing about using a variable to find the camera focus. https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html shows how to set focus mode, but I can't find anything on setting a custom focus or viewing what the camera is focused on. If you want to take a picture and do some sort of custom pixel by pixel analysis to see how it's focused, by all means go ahead. Maybe a jail-broken iPhone can access camera focus, but I'm guessing that your target audience is more then the select group that have gone through the jail-breaking process.

I think the easiest way to find the height is to have them point their phone down at their foot. Then you can ask them shoe size and brand to estimate the width of their shoe, or just make a flat out guess. Just ask them to point at the side of their shoe, perhaps by displaying a red dot in the middle of the screen so they know exactly where they're pointing. Then ask them to point at the other and then, once you have captured both edges of their shoe, use the estimated inch width of their shoe multiplied by the tan of the angle difference from one edge to the other (so if it is 170 degrees when pointed at one edge and 190 when at the other use the tan of 20). That should give you the height in inches off the ground.

    s = shoe width;    ao = angle when pointed at left shoe edge (y-axis)(radians);    at = angle when pointed at right shoe edge (y-axis)(radians);    a = angle of device when pointed at the point on the ground (x-axis)(radians);    d = distance;    d = atan(a) * tan(at - ao) * s;


Its not possible way to get distance while varying ground-mobile distance dynamically from each person. Manually user have to set the height of the mobile each time to calculate.