6

In iphone, I want to calculate the distance from the camera to the subject.

I was wondering maybe iphone camera's "Active Auto Focus" provide me the distance to the subject (point of interest)??

many thanks in advance.

p.s. guys if you think it is not possible plz let me know ;)

Nima
  • 969
  • 3
  • 10
  • 14

2 Answers2

1

As far as I'm aware, it's not possible - see here for more info on what you can and can't do. You can tell when the camera is autofocusing, but nothing more.

I'm sure there is probably some more info you can get on focus/distance using a private API call - but unless you're not worried about getting on the App Store, it's not really an option.

That doesn't mean there's not another way though. Looks like a good discussion on the topic here: Distance using OpenCV (you can compile openCV for iOS!)

Community
  • 1
  • 1
Jordan Smith
  • 10,310
  • 7
  • 68
  • 114
  • Thanks Jordan for the response, unfortunately I dont have any prior info on my picture like any object with a known size, the only thing i know is that the object is between 20 cm to 2 meter. – Nima Jun 30 '11 at 14:48
0

I've been investigating the ability of the camera to measure short distances and not finding anything yet I came up with this shot in the dark. I haven't tried it yet, but the docs make me think this might work:

  • Create and configure an AVCaptureDevice representing the camera
  • Through the AVCaptureSession, capture the AVCaptureStillImageOutput
  • From the AVCaptureStillImageOutput object check the Exif properties for kCGImagePropertyExifSubjectDistance

Love to hear if anyone has been able to use a methodology like this to be able to make accurate (less than 1 foot) distance measurements.

Dan Loughney
  • 4,647
  • 3
  • 25
  • 40
  • 1
    This turns out to be a dead end. I was able to test the procedure using the AvCam sample. I checked the data in the CMSampleBufferRef object returned by AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection and while it did contain 20 EXIF values, kCGImagePropertyExifSubjectDistance was not one of them--even on an iPhone 5S. – Dan Loughney Jan 08 '14 at 14:12