8

From AVFoundation objects like AVCaptureDevice I can read a value of fieldOfView using

captureDevice.activeFormat.videoFieldOfView

And this gives me a value of about 58 degrees on iPhone 6s. But what I need is to get current value of actual fieldOfView displayed in current frame while AVCaptureSession is running. What I mean by this is that the value read from activeFormat does not reflect real fieldOfView when lens is moved to get image in focus. For example when I point camera at a distant object, lens moves to keep in focus, and fieldOfView increases a little bit, to about 61 degrees. You can observe this behavior in ARKit camera - even when camera is catching focus displayed objects are getting bigger and smaller focusing along with the camera preview. I would like to know how can I achieve such behavior and adjust fieldOfView to current lens position. I need to apply this to SceneKit camera.

In shortcut: How to find current exact FieldOfView of camera taking into consideration current focus position (or lens position)

To help understand what I mean please look at this gif:

Focusing on iPhone

At the beginning you can see it focusing, and video kinda like zoomes in/out a little to catch correct lens position. So when this lens moves actual visible fieldOfView is getting a little different.

Damian Dudycz
  • 2,622
  • 19
  • 38
  • 1
    The closest value I can think of to get close to resolve this is `AVCaptureDevice.lensPosition`. This value goes from 0.0 to 1.0 when sharpening image to get focused. But value from 0 to 1 doesn't give me enough information, I don't know how this affect fieldOfView exactly. Are there some other values I could use to calculate this? – Damian Dudycz Jul 18 '18 at 19:17
  • I couldn't find any Apple API besides that you have already discovered. Here is little tip. In order to get updated `lensPosition`and `fieldOfView ` values you can attach `CADisplayLink`. But `fieldOfView` seems to have no difference when lens position or zoom changes anyway, so I guess you should find proper formulas online. :( – Denis Litvin Jul 25 '18 at 14:15
  • Thanks for comment. I already use display link so yep, this is the place where I would calculate this, but I can’t find formulas anywhere. I don’t think that I can find any formulas online, because these values I have are not enough. It would be if lensPosition was in mm, but it’s just some arbitrary value from 0 to 1. I even sent a tsi to Apple, but with no response so far. I’m thinking about measuring maximum fov by hand from image, and then use lensPosition to add difference from reported fov times lens position. This could work but would not be very accurate and different for other devices – Damian Dudycz Jul 25 '18 at 23:00
  • 3
    I have just recieved response from Apple, confirming that this is impossible to do using public api. I’m left with using hardcoded estimations. They suggested me to fill a request to implement this in future releases. – Damian Dudycz Jul 26 '18 at 06:00
  • 1
    Ok I have implemented a resolution to this as I stated before - I measured actual fields of view of camera using ARKit for when lensPosition is at 0 and at 1. And for these values for iPhone 6s actual field of view can differ from returned field of view between -0.24167252 ..< 3.3269768. And this works perfect, I measured this using real objects and applying their size and distance, and it works perfect. Is there maybe some other way I could get these values for other devices without measuring them manually from ARKit? I need to fill dictionary with values for various devices. – Damian Dudycz Aug 14 '18 at 06:20
  • have a look at this answer: https://stackoverflow.com/a/47643149/9497657 – AD Progress Sep 04 '18 at 10:47
  • 1
    @DamianDudycz, any chance you could share your work on measuring the `fieldOfView` at different `lensPosition`s? I'm currently working on something similar where I need the current fieldOfView of my active iOS camera session -- which cannot be an ARKit session, but I do notice that the constant `fieldOfView` returned from iOS is not good enough for my use case. It would be awesome if I didn't have to redo the same work you did... – Carsten Haubold Mar 04 '19 at 17:09

0 Answers0