How to calculate FOV? How to calculate FOV? ios ios

# How to calculate FOV?

In iOS 7 and above you can do something along these lines:

``float FOV = camera.activeFormat.videoFieldOfView;``

where `camera` is your `AVCaptureDevice`. Depending on what preset you choose for the video session, this can change even on the same device. It's the horizontal field-of-view (in degrees), so you'll need to calculate the vertical field-of-view from the display dimensions.

Here's Apple's reference material.

Do my method and my formula look right...?

Maybe, but they also look too complex.

...and if yes, which values do I pass to the function?

I don't know, but if the goal is to calculate HFOV and VFOV, here is a code example which programmatically finds the Horizontal Viewing Angle, which is the only viewing angle one can access in Swift currently, and then calculates the Vertical Viewing Angle based on the aspect ratio of the iPhone 6, 16:9.

``    let devices = AVCaptureDevice.devices()    var captureDevice : AVCaptureDevice?    for device in devices {        if (device.hasMediaType(AVMediaTypeVideo)) {            if(device.position == AVCaptureDevicePosition.Back) {                captureDevice = device as? AVCaptureDevice            }        }    }    if let retrievedDevice = captureDevice {        var HFOV : Float = retrievedDevice.activeFormat.videoFieldOfView        var VFOV : Float = ((HFOV)/16.0)*9.0    }``

Also remember to import AVFoundation if you want this to work!

Apple has also released a list with all camera specification details including FOV (Field of View).

https://developer.apple.com/library/ios/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html

The values match the values that can be retrieved using:

`float FOV = camera.activeFormat.videoFieldOfView;`